Hello nemesis,
many thanks for your reply, I very much appreciate your answer.
As vertices themselve an not visible, I actually referred to the tris, tristrips, lines etc. you would add to a Geom using addPrimitive, like this:
self.vertex_data = GeomVertexData(name, self.format, Geom.UHStatic)
self.tristrips = GeomTristrips(Geom.UHStatic)
self.vertex = GeomVertexWriter(self.vertex_data, 'vertex')
#[..]
_v0 = self.vertex.getWriteRow()
self.vertex.addData3f(x1, y1, z1)
self.vertex.addData3f(x2, y1, z1)
self.vertex.addData3f(x2, y2, z2)
self.vertex.addData3f(x1, y2, z2)
self.tristrips.addVertices(_v0, _v0 + 1, _v0 + 3, _v0 + 2)
self.tristrips.closePrimitive()
#[..]
geom_node = GeomNode(self.name)
mesh = Geom(self.vertex_data)
mesh.addPrimitive(self.tristrips)
geom_node.addGeom(mesh)
So yes, I think that is what I mean.
This is exactly the type of answer I hoped to get, clear and precise, thanks!
Only for information:
I wanted to keep my question simple and general, that’s why I did not go into detail with my initial post.
In a first try I thought to use flattenString to reduce the number of used nodes/geoms. Because using the predefined boxes would be convenient and simple. It looked like this:
BLOCK_CHOICE = [0, 1, 2]
BLOCK_COLOR_MAP = {0: (0, 0, 0, 1),
1: (0.5, 0.5, 0.5, 1),
2: (1, 1, 1, 1)
}
# Load the box
box = loader.loadModel("box")
# Make sure its center is at 0, 0, 0 like OdeBoxGeom
box.setPos(-.5, -.5, -.5)
box.flattenLight() # Apply transform
box.setTextureOff()
def create_chunk(n, name="Chunk"):
chunk_node = render.attachNewNode(name)
for z in xrange(n):
for y in xrange(n):
for x in xrange(n):
if not z or not y or not x or z==n-1 or y == n-1 or x==n-1:
block_type = choice(BLOCK_CHOICE)
np = chunk_node.attachNewNode("Base Box %i %i %i" % (x, y, z))
copy = box.copyTo(np)
copy.setPos(x, y, z)
copy.setColor(*BLOCK_COLOR_MAP.get(block_type))
chunk_node.flattenStrong()
return chunk_node
# Add a random amount of boxes
boxes = []
n=10
for z in xrange(3):
for y in xrange(3):
for x in xrange(3):
boxes.append((x, y, z))
np = render.attachNewNode("Base Box")
copy = box.instanceTo(np)
copy.setPos(0, 0, 0)
copy.setColor(0.5, 0.5, 0.5, 1)
# Set the camera position
base.disableMouse()
base.camera.setPos(60, 60, 40)
base.camera.lookAt(0, 0, 0)
#[..]
def build_task(task):
if boxes:
x, y, z = boxes.pop()
chunk_name = "Chunk %i %i %i" % (x, y, z)
print "generating", chunk_name
chunk = create_chunk(n, chunk_name)
chunk.setPos(x*n, y*n, z*n)
task.setDelay(1)
return task.again
taskMgr.doMethodLater(1, build_task, "Chunk Build Task")
run()
I have created 3x3x3 = 27 flattened chunks of cubes, where I already took care to only draw the bounding boxes (x, y, z = 0 or n-1).
But still: as long as the block of chunks is only partially on screen, everything runs fluently. But as soon as I get all into view, the framerate drops significantly.
(I use a GeForce GTX 560 and usually have no problems with Minecraft using HD texture packs.)
Actually I was really surprised. I didn’t think that the (estimated) < 20k cube models would be so expensive. Therefore my questions, whether it was the amound of visible elements or use of geoms that made the framerate drop. Maybe I should have asked for the cost of models instead of geoms.
BR,
Michael