i’m playing around with volumes/voxels and surface extraction. i just got my marching cubes algorithm working and now i wanted to render the geometry with panda. there is just one little problem. the objekt is all flat, there is no light or shadow. i added ambient light to render and to the nodepath of the object, but nothing happened.
heres a picture:
any ideas? i did not know with which keywords to search for this in the forums, so please don’t be mad if this is something what has been answered a thousand times…
i added a directional light to the object but nothing happened…
i tried to place the lights an the object with the nodePath.place() method. when moving and rotating the procedurally generated object its color changed, so i think the lights do have an influence on it. but there was no shading.
here is the code i’m using for the light and for generating the geometry:
# Create Ambient Light
ambientLight = AmbientLight('ambientLight')
ambientLight.setColor(Vec4(0.1, 0.1, 0.1, 1))
ambientLightNP = render.attachNewNode(ambientLight)
render.setLight(ambientLightNP)
# Directional light 01
directionalLight = DirectionalLight('directionalLight')
directionalLight.setColor(Vec4(0.8, 0.2, 0.2, 1))
directionalLightNP = render.attachNewNode(directionalLight)
# This light is facing backwards, towards the camera.
directionalLightNP.setHpr(180, -20, 0)
render.setLight(directionalLightNP)
# Directional light 02
directionalLight = DirectionalLight('directionalLight')
directionalLight.setColor(Vec4(0.2, 0.2, 0.8, 1))
directionalLightNP = render.attachNewNode(directionalLight)
# This light is facing forwards, away from the camera.
directionalLightNP.setHpr(0, -20, 0)
#directionalLightNP.place()
render.setLight(directionalLightNP)
# Create and register GeomVertexFormat
format = GeomVertexFormat.getV3()
format = GeomVertexFormat.registerFormat(format)
# Create GeomVertexData and Writers for vertices, normals and colors
vdata = GeomVertexData('Cube', format, Geom.UHDynamic)
vertex = GeomVertexWriter(vdata, 'vertex')
tris = self.mesh.triangles
volume = self.volume
extractor = self.extractor
mesh = self.mesh
#volume.randomize()
volume.generateCube()
extractor.extractSurface(volume, mesh)
# Add some Data to the Tables ( iterate through given surface)
for i in range(len(tris)):
vertex.addData3f(tris[i][0][0], tris[i][0][1], tris[i][0][2])
vertex.addData3f(tris[i][1][0], tris[i][1][1], tris[i][1][2])
vertex.addData3f(tris[i][2][0], tris[i][2][1], tris[i][2][2])
# Create a primitive which is using the vertices
prim = GeomTriangles(Geom.UHDynamic)
for j in range(1, len(tris)):
prim.addVertex(j)
prim.addVertex(j+1)
prim.addVertex(j+2)
prim.closePrimitive()
# Create Geom and add primitives
geom = Geom(vdata)
geom.addPrimitive(prim)
# Create Node and add Geom
node = GeomNode('gnode')
node.addGeom(geom)
nodePath = render.attachNewNode(node)
nodePath.setCollideMask(BitMask32.bit(1))
#nodePath.setTexture(self.texture)
nodePath.setTwoSided(True)
nodePath.setLight(ambientLightNP)
nodePath.setLight(directionalLightNP)
#nodePath.place()
You will also need to compute a normal for each vertex of your geometry, and store that in your GeomVertexData. The lighting calculation is made based on the vertex position and the normal at that vertex; without normals, you will get only a random, flat shade.
Hi Loschi, remember me from thermite3d? Looks like me and you have exactly the same things in mind
It’s a shame there’s no other package like Polyvox with a good python interface, or at least a package that is easier to wrap for a python interface.
Sure Initially it was for my Bachelor Thesis. I was writing about realtime destruction in virtual gaming environments. (My university is NOT into gaming OR computer graphics, so i picked this topic on my own risk )
And now, after i’m done writing, i just want to play around with panda and volumes/voxels to create a stone/wood carving game. In the fashion of “colors by numbers” i want the game to be “carving by colors”. There is a white boulder and inside it there are colored layers which are getting more and more detailed. The last layer will be the finished figure.
I think i will try to wrap PolyVox again. PolyVox-David proposed to create a simpler c++ class which wraps the needed functionality of PolyVox and then wrap this simpler class for python. I hope my rusty c++ will suffice