It looks like you're new here. If you want to get involved, click one of these buttons!
local nbc, nbr = 8, 8 -- number of columns, number of rows local minh, maxh = 0, 2 -- min height, max height local ht = { -- heights table example 0,0,0,0,0,0,0,0, 0,1,1,1.5,0,0,0,0, 0,1,1,1.5,1,0.5,0,0, 0,0,1.5,2,2,2,0,0, 0,0,0,2,2,2,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, } local mesh = HeightField3Db.new(nbc, nbr, ht) -- problem building the corresponding mesh local view = Viewport.new() view:setContent(mesh) view.body = xworld:createBody(view:getMatrix()) -- the collision shape local shape = r3d.HeightFieldShape.new(nbc, nbr, minh, maxh, ht) -- collision is ok but I need to build its mesh! shape:setScale(5,5,5) |
local HeightField3Db=Core.class(Mesh3Db) function HeightField3Db:init(nbc, nbr, ht) -- num of cols, num of rows, heights table local va,ia,na={},{},{} local i, j = 1, 1 for y = 1, nbr do -- XXX I am lost for the index array :-( for x = 1, nbc do local a = y*nbc+x ia[i+0]= j ia[i+1]= j+1 ia[i+2]= a ia[i+3]= j ia[i+4]= a ia[i+5]= a-1 j += 1 end end -- na={ 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1, 0,0,1, 0,0,1, 0,0,1, 0,0,1, } i, j = 1, 1 for y = 1, nbr do -- the vertex array is fine :-) for x = 1, nbc do va[i+0]=x va[i+1]=ht[j] va[i+2]=y i+=3 j+=1 end end -- self:setGenericArray(3,Shader.DFLOAT,3,24,Box3Db.na) self:setVertexArray(va) -- good self:setIndexArray(ia) -- bad self._va=va self._ia=ia end |
Comments
And I join a sample project.
error: "Cannot use object of type stdClass as array"
I posted the project on GH: https://github.com/mokalux/gideros-3D-FP-forum
Likes: MoKaLux
Almost there
one more question pleaseDo you think we can calculate the normals for the texture on this shape?EDIT: this should be working
we can walk on terrains.
I am stuck here because I need to retrieve the normals of the terrain and it's complicated. I have read that r3d automatically calculates normal of the terrain but I don't know how it does it (it's maybe in the GH source somewhere).
That would be nice to have a function in gideros that returns this information so we can use it when building the mesh and for texturing as well.
I will tidy up the code and put the new terrain on GH.
PS: I also have R3d.ConcaveMeshShape working (but still a mess with the normals too).
Will try to work on it later...