I have some code that creates a sphere using the EggData system, and I want to alter the colours of the sphere in python.
I was going to use the following code that is based on code in another thread:
def manipulateGeom(geom):
geomNode = geom.find('**/+GeomNode').node()
vertexArray = geomNode.getGeom(0).getCoordsArray()
size = vertexArray.size()
#do stuff with vertices
This function works fine for any egg files loaded from disk, however the vertexArray returns an incorrect (small) list of vertices for a sphere I create using loadEggData. Should I be doing anything different here?
The following code creates a sphere in panda correctly(it has normals, texture coords and is the right size) but when I call manipulateGeom on it it gives me a vertex size of 6. However calling manipulateGeom on the planet sphere that comes with the basic panda samples returns 700 odd vertices.
def createSphere(r, nRings = 32, nSegments = 32):
data = EggData()
vp = EggVertexPool('triangle')
data.addChild(vp)
fDeltaRingAngle = (math.pi / nRings);
fDeltaSegAngle = (2 * math.pi / nSegments);
wVerticeIndex = 0
vertexList = [] #keep our own list of vertices so we can create shared vertices easily
# Generate the group of rings for the sphere
for ring in range(nRings +1):
r0 = r * math.sin (ring * fDeltaRingAngle);
y0 = r * math.cos (ring * fDeltaRingAngle);
# Generate the group of segments for the current ring
for seg in range(nSegments+1):
x0 = r0 * math.sin(seg * fDeltaSegAngle);
z0 = r0 * math.cos(seg * fDeltaSegAngle);
# Add one vertex to the strip which makes up the sphere
v = EggVertex()
p = Point3D(x0, z0, -y0) #this code was originally from a different coord system
v.setPos(p)
n = Vec3D(p)
n = n / n.length()
v.setNormal(n)
v.setUv(Point2D(seg / float(nSegments), ring / float(nRings)))
vp.addVertex(v)
vertexList.append(v) #add to temp list
for ring in range(nRings +1):
for seg in range(nSegments+1):
if (ring != nRings):
poly = EggPolygon()
data.addChild(poly)
poly.addVertex(vertexList[wVerticeIndex + nSegments + 1])
poly.addVertex(vertexList[wVerticeIndex])
poly.addVertex(vertexList[wVerticeIndex + nSegments])
poly = EggPolygon()
data.addChild(poly)
poly.addVertex(vertexList[wVerticeIndex + nSegments + 1])
poly.addVertex(vertexList[wVerticeIndex + 1])
poly.addVertex(vertexList[wVerticeIndex])
wVerticeIndex += 1
node = loadEggData(data)
return NodePath(node)
help!