I’ve been searching all over for a solution to modify the vertices of a geom but i’m out of luck.
What i’m trying to accomplish is to remove certain triangles after they have been added to a primitive, and my first approach would be to just set the vertex coordinates to (0,0,0) for all the sides of the triangle to make it not visible since I’m looking for speed rather than a good structured table of vertices (The geom may contain serveral hundred thousand vertices). If anyone has a better solution I would really appriciate an example of this.
So to the code:
Declaring the geom:
def createGeom(self):
format = GeomVertexFormat.getV3n3cpt2()
gvd = GeomVertexData('materialGvd', format, Geom.UHDynamic)
geom = Geom(gvd)
gvdPrim = GeomTriangles(Geom.UHDynamic)
gvdVertex = GeomVertexWriter(gvd, 'vertex')
gvdNormal = GeomVertexWriter(gvd, 'normal')
gvdTexcoord = GeomVertexWriter(gvd, 'texcoord')
gvdColor = GeomVertexWriter(gvd, 'color')
gvdTex = loader.loadTexture('textures/2_.png')
gvdTex.setMagfilter(Texture.FTLinearMipmapLinear)
gvdTex.setMinfilter(Texture.FTLinearMipmapLinear)
geoms = {'geom':geom,
'prim':gvdPrim,
'vertex':gvdVertex,
'normal':gvdNormal,
'texcoord':gvdTexcoord,
'color':gvdColor,
'index':0,
'gvd':gvd,
'texture':gvdTex}
geomNode = GeomNode('material')
geoms['geom'].addPrimitive(geoms['prim'])
geomNode.addGeom(geoms['geom'])
chunkNode = render.attachNewNode(geomNode)
chunkNode.setPos(Vec3(0,0,0))
chunkNode.setTwoSided(False)
chunkNode.setCollideMask(BitMask32.allOff())
return chunkNode,geomNode,geoms,gvd
With this code I then add a bunch of vertices:
def writeMaterial(self,geoms,displacement,faces,color):
for v in faces:
# format of v: "Vec3(20,0,20)" and so forth
displacement = self.createMesh(geoms,displacement,v,color)
return displacement
def createMesh(self,geoms,displacement,v,color):
geoms['vertex'].addData3f(v)
geoms['color'].addData4f(color)
geoms['prim'].addVertex(displacement)
displacement += 1
return displacement
The displacement of the first and last vertex is stored so it can later be accessed and modified with this code:
#mD is an array with this format: "[0,35]", where 0 is the first vertex and 35 is the last vertex that I want to modify.
geom = geomNode.modifyGeom(0)
vdata = geom.modifyVertexData()
prim = geom.modifyPrimitive(0)
vertexWriter = GeomVertexWriter(vdata, 'vertex')
vertexReader = GeomVertexReader(vdata, 'vertex')
row = 0
mdCounter = mD[0]
while not vertexReader.isAtEnd():
vr = vertexReader.getData3f()
if row == mdCounter and row <= mD[1]:
vr = Vec3(0,0,0)
mdCounter += 1
print "Deleteed row ",row
vertexWriter.setData3f(vr)
row += 1
(Sorry for not posting a better view of the code but it’s spread over several files so it’s hard to make a good overview of it)
Unfortunatly i can’t seem to get this to work correctly. Do I need to apply the changes to the primitive/geom somehow? When I add vertices the changes (new triangles) appear instantly.