About Store Forum Documentation Contact



Post Reply 
Heightmap setMaterial issue
Author Message
SamerK Offline
Member

Post: #1
Heightmap setMaterial issue
Hi,

Please, if anyone can help me. I have a project require a direct height map creation and manipulation. Everything worked perfectly using EE2 Heightmap functions, but when I started manually accessing HM vertex data like position or normals (using e.g. HMmesh.parts.data().base.vtx.nrm(h).y ) I found the HM vertex count get distorted after using heightmap.setMaterial(....) function, as a result this caused the HM to deform strangely and sometimes crashes with "out of range error !"

I attached an example using EE2 heightmap tutorial to illustrate the issue.
please add/remove heightmap.setMaterial(....); line in the code to see the difference.


Thanks


Attached File(s)
.txt  HMtest.txt (Size: 3.73 KB / Downloads: 9)
(This post was last modified: 08-11-2013 07:41 PM by SamerK.)
08-11-2013 06:45 PM
Find all posts by this user Quote this message in a reply
Patalarc Offline
Member

Post: #2
RE: Heightmap setMaterial issue
Hi

when creating a mesh with Build, different parts are created automatically depending on the materials used, in this way you can create terrain with many different materials

remove the line heightmap.setMaterial(....) and change mesh.draw(...) by:

mesh.parts(0).draw(MatrixIdentity);

there you can see the initial part of the mesh, to see the other parts change it to:

mesh.parts(1).draw(MatrixIdentity);

you're changing the vertex only in parts(0). (To see this you can add again heightmap.setMaterial (....) and see that only modified parts(0), the parts(1) remains unchanged)

the problem is that when creating new parts, the position of the index of the vertex are modified, that is why moving the vertex look messy.

to modify the mesh you would have to move each vertex of each parts to the right position, but i do not know in what way build sorts the vertex to create each part.

about the error that occurs sometimes, not sure but it may be because you try to access index of vertex of the parts(0) that no longer exist, because they went to parts(1) or some problem like that.
08-11-2013 10:17 PM
Find all posts by this user Quote this message in a reply
SamerK Offline
Member

Post: #3
RE: Heightmap setMaterial issue
Thank you Patalarc, I agree with your analysis, actually the main issue revolve around the fact that HM mesh index count changes when applying materials which also cause "out of range issue" crash because my code is not considering this change.

note that the same issue also repeated when trying to update vertex normals only ... it seams EE heightmaps dos not like anyone to touch their vertices smile .

I don't think its practical to re-sort all vertices for each time I want to apply a material as my objective is to edit the HM vertices dynamically.

Maybe Esenthel can guide for better approach to get around this issue.

Thanks again
(This post was last modified: 08-12-2013 01:57 PM by SamerK.)
08-11-2013 11:47 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Heightmap setMaterial issue
Hi!

Yes the vtx count can be changed if you modify materials smile
Different material combinations need to be set as separate MeshParts, please keep that in mind, and don't assume that vtx count will remain the same.
08-14-2013 09:11 PM
Find all posts by this user Quote this message in a reply
SamerK Offline
Member

Post: #5
RE: Heightmap setMaterial issue
Thank you Esenthel.
08-14-2013 09:29 PM
Find all posts by this user Quote this message in a reply
Post Reply