Yeah I do to some degree, but something is still not clear to me. Here is code that generates a box from within the game, for example:
def gameBox(self,quadSide):
widthIs=4
lengthIs=4
heightIs=4
if(quadSide==1):
#back:
point1=Point3(0-widthIs,0,0)
point2=Point3(0+widthIs,0,0)
point3=Point3(0-widthIs,0,0+heightIs)
point4=Point3(0+widthIs,0,0+heightIs)
elif(quadSide==2):
#front:
point1=Point3(0-widthIs,0+lengthIs,0)
point2=Point3(0+widthIs,0+lengthIs,0)
point3=Point3(0-widthIs,0+lengthIs,0+heightIs)
point4=Point3(0+widthIs,0+lengthIs,0+heightIs)
elif(quadSide==3):
#left:
point1=Point3(0-widthIs,0,0)
point2=Point3(0-widthIs,0+lengthIs,0)
point3=Point3(0-widthIs,0,0+heightIs)
point4=Point3(0-widthIs,0+lengthIs,0+heightIs)
elif(quadSide==4):
#right:
point1=Point3(0+widthIs,0,0)
point2=Point3(0+widthIs,0+lengthIs,0)
point3=Point3(0+widthIs,0,0+heightIs)
point4=Point3(0+widthIs,0+lengthIs,0+heightIs)
elif(quadSide==5):
#top:
point1=Point3(0-widthIs,0,0+heightIs)
point2=Point3(0+widthIs,0,0+heightIs)
point3=Point3(0-widthIs,0+lengthIs,0+heightIs)
point4=Point3(0+widthIs,0+lengthIs,0+heightIs)
elif(quadSide==6):
#bottom:
point1=Point3(0-widthIs,0,0)
point2=Point3(0+widthIs,0,0)
point3=Point3(0-widthIs,0+lengthIs,0)
point4=Point3(0+widthIs,0+lengthIs,0)
x1=point1.x
y1=point1.y
minZ=point1.z
#1.vertex:
vertex.addData3f(x1,y1, minZ)
normData=self.normalizer(Vec3(2*x1-1, 2*y1-1, 2*minZ-1))
normal.addData3f(normData.x,normData.y,normData.z)
color.addData4f(1, 1, 1, 1)
texcoord.addData2f(0, 0)
x2=point2.x
y2=point2.y
minZ=point2.z
#2.vertex:
vertex.addData3f(x2,y2, minZ)
normData=self.normalizer(Vec3(2*x2-1, 2*y2-1, 2*minZ-1))
normal.addData3f(normData.x,normData.y,normData.z)
color.addData4f(1, 1, 1, 1)
texcoord.addData2f(1, 0)
x3=point3.x
y3=point3.y
minZ=point3.z
#3.vertex:
vertex.addData3f(x3,y3, minZ)
normData=self.normalizer(Vec3(2*x3-1, 2*y3-1, 2*minZ-1))
normal.addData3f(normData.x,normData.y,normData.z)
color.addData4f(1, 1, 1, 1)
texcoord.addData2f(0, 1)
x4=point4.x
y4=point4.y
minZ=point4.z
#4.vertex:
vertex.addData3f(x4,y4, minZ)
normData=self.normalizer(Vec3(2*x4-1, 2*y4-1, 2*minZ-1))
normal.addData3f(normData.x,normData.y,normData.z)
color.addData4f(1, 1, 1, 1)
texcoord.addData2f(1, 1)
#add to primitive:
tris = GeomTriangles(Geom.UHDynamic)
tris.addVertices(0, 1, 2)
tris.addVertices(1, 2, 3)
square = Geom(vdata)
square.addPrimitive(tris)
self.vertex_pool_data.append([point1,point2,point3,point4])
return square
nodeTile = GeomNode("foundationTileGeomNode")
for i in range(6):
gotGeom=self.gameBox(i+1)
nodeTile.addGeom(gotGeom)
gameCube = render.attachNewNode(nodeTile)
gameCube.setTwoSided(True)
gameCube.setTransparency(TransparencyAttrib.MAlpha,1)
So from this code above, the points I’m using to define the cube that go into the “vertex.addData3f(x,y,z)” and that I use to define the normal data later on, those are global points in the world space, correct?
Now, here is that bit of code that will write the points as a vertex pool into the egg file:
vp = EggVertexPool('boxi2')
transformz=EggTransform()
#scale:
transformz.addScale3d(VBase3D(gameCube.getSx(render),gameCube.getSy(render),gameCube.getSz(render)))
#rotation:
transformz.addRoty(gameCube.getR(render))
transformz.addRotx(gameCube.getP(render))
transformz.addRotz(gameCube.getH(render))
#translation:
transformz.addTranslate3d(VBase3D(gameCube.getX(render),gameCube.getY(render),gameCube.getZ(render)))
mat=transformz.getTransform3d()
...
#iterate through the point data used to define the box earlier and add it to the vertex pool:
faceData=self.vertex_pool_data[currentIndex]
p1=faceData[0]
p2=faceData[2]
p3=faceData[4]
p4=faceData[6]
v=EggVertex()
v.setPos(Point3D(p1.x,p1.y,p1.z))
v.transform(mat)
vp.addVertex(v)
Okay, so after filling the vertex pool with data, I use the points inside it to generate the normals that will go into the egg file (there’s some other stuff I do in between which is why I write it out at a separate portion of the code):
#now, get the point data added to the vertex pool and generate normals from it
#then write it out to the egg file:
vrtx=vp.getVertex(runningIndex)
pozzi=vrtx.getPos3()
#write out the normal data using this point:
self.f_wrt.write("<Normal> { ")
retz=self.normalizer(Vec3(2*pozzi.x-1, 2*pozzi.y-1, 2*pozzi.z-1))
self.f_wrt.write(str(retz.x)+" "+str(retz.y)+" "+str(retz.z)+" } ")
So…the points I’d be writing into the egg file, they are the global points of the box in the world, right? When generating procedural geometry, I just specify where each point and face should be, I never really thought about its local origin. In short, what should I do to a point used to define the box, before using it to generate normals and then writing those normals into the file, like in the example above?