# Setting texture via egg library

Hi to all,

I am using the egg library to try and write out the procedural geometry I am generating, and the first of my problems relates to adding a texture to the geometry, and then modifying the scale, offset and rotation of said texture. Firstly, I have gotten this far in writing the geometry:

``````horiz_a=[Point3(0, 0, 0), Point3(4, 0, 0), Point3(0, 0, 4), Point3(4, 0, 4), Point3(0, 8, 0), Point3(4, 8, 0), Point3(0, 8, 4), Point3(4, 8, 4)]

def myNormalize(myVec):
myVec.normalize()
veki=Vec3D(myVec.x,myVec.y,myVec.z)
return veki

def makeBox():
data = EggData()
data.setCoordinateSystem(0)
#texture data:
textz=EggTexture("texture_a",Filename.fromOsSpecific("lava_two.jpg"))
textz.setUvName("uva_textz")
#some group stuff:
grupo=EggGroup("GRUPO_UR")
gtype=Enum('GTGroup')
grupo.setGroupType(gtype.GTGroup)
#vertex pool:
vp = EggVertexPool('boxi')
for i in range(0,len(horiz_a),8):
#first face:
poly = EggPolygon()
v = EggVertex()
v.setPos(Point3D(horiz_a[i+3].x,horiz_a[i+3].y,horiz_a[i+3].z))
#set its normal:
v.setNormal(myNormalize(Vec3(2*horiz_a[i+3].x-1, 2*horiz_a[i+3].y-1, 2*horiz_a[i+3].z-1)))
#set it's color:
#v.setColor(VBase4(1,1,1,0.4))
#set it's uvs:
v.setUv("uva_textz",Point2D(1,0))
grupo.refVertex(v)
#grupo.refPolygon(poly)

v2 = EggVertex()
v2.setPos(Point3D(horiz_a[i+2].x,horiz_a[i+2].y,horiz_a[i+2].z))
#set its normal:
v2.setNormal(myNormalize(Vec3(2*horiz_a[i+2].x-1, 2*horiz_a[i+2].y-1, 2*horiz_a[i+2].z-1)))
#set it's uvs:
v2.setUv("uva_textz",Point2D(1,1))
grupo.refVertex(v2)

v3 = EggVertex()
v3.setPos(Point3D(horiz_a[i].x,horiz_a[i].y,horiz_a[i].z))
#set its normal:
v3.setNormal(myNormalize(Vec3(2*horiz_a[i].x-1, 2*horiz_a[i].y-1, 2*horiz_a[i].z-1)))
#set it's uvs:
v3.setUv("uva_textz",Point2D(0,1))
grupo.refVertex(v3)

v4 = EggVertex()
v4.setPos(Point3D(horiz_a[i+1].x,horiz_a[i+1].y,horiz_a[i+1].z))
#set its normal:
v4.setNormal(myNormalize(Vec3(2*horiz_a[i+1].x-1, 2*horiz_a[i+1].y-1, 2*horiz_a[i+1].z-1)))
#set it's uvs:
v4.setUv("uva_textz",Point2D(0,0))
grupo.refVertex(v4)

#back-face:
poly.setBfaceFlag(True)

#second face:
poly = EggPolygon()
v = EggVertex()
v.setPos(Point3D(horiz_a[i+7].x,horiz_a[i+7].y,horiz_a[i+7].z))
#set its normal:
v.setNormal(myNormalize(Vec3(2*horiz_a[i+7].x-1, 2*horiz_a[i+7].y-1, 2*horiz_a[i+7].z-1)))
#set it's uvs:
v.setUv("uva_textz",Point2D(1,0))
grupo.refVertex(v)

v2 = EggVertex()
v2.setPos(Point3D(horiz_a[i+6].x,horiz_a[i+6].y,horiz_a[i+6].z))
#set its normal:
v2.setNormal(myNormalize(Vec3(2*horiz_a[i+6].x-1, 2*horiz_a[i+6].y-1, 2*horiz_a[i+6].z-1)))
#set it's uvs:
v2.setUv("uva_textz",Point2D(1,1))
grupo.refVertex(v2)

v3 = EggVertex()
v3.setPos(Point3D(horiz_a[i+4].x,horiz_a[i+4].y,horiz_a[i+4].z))
#set its normal:
v3.setNormal(myNormalize(Vec3(2*horiz_a[i+4].x-1, 2*horiz_a[i+4].y-1, 2*horiz_a[i+4].z-1)))
#set it's uvs:
v3.setUv("uva_textz",Point2D(0,1))
grupo.refVertex(v3)

v4 = EggVertex()
v4.setPos(Point3D(horiz_a[i+5].x,horiz_a[i+5].y,horiz_a[i+5].z))
#set its normal:
v4.setNormal(myNormalize(Vec3(2*horiz_a[i+5].x-1, 2*horiz_a[i+5].y-1, 2*horiz_a[i+5].z-1)))
#set it's uvs:
v4.setUv("uva_textz",Point2D(0,0))
grupo.refVertex(v4)

#back-face:
poly.setBfaceFlag(True)

#third face:
poly = EggPolygon()
v = EggVertex()
v.setPos(Point3D(horiz_a[i+6].x,horiz_a[i+6].y,horiz_a[i+6].z))
#set its normal:
v.setNormal(myNormalize(Vec3(2*horiz_a[i+6].x-1, 2*horiz_a[i+6].y-1, 2*horiz_a[i+6].z-1)))
#set it's uvs:
v.setUv("uva_textz",Point2D(1,0))
grupo.refVertex(v)

v2 = EggVertex()
v2.setPos(Point3D(horiz_a[i+2].x,horiz_a[i+2].y,horiz_a[i+2].z))
#set its normal:
v2.setNormal(myNormalize(Vec3(2*horiz_a[i+2].x-1, 2*horiz_a[i+2].y-1, 2*horiz_a[i+2].z-1)))
#set it's uvs:
v2.setUv("uva_textz",Point2D(1,1))
grupo.refVertex(v2)

v3 = EggVertex()
v3.setPos(Point3D(horiz_a[i].x,horiz_a[i].y,horiz_a[i].z))
#set its normal:
v3.setNormal(myNormalize(Vec3(2*horiz_a[i].x-1, 2*horiz_a[i].y-1, 2*horiz_a[i].z-1)))
#set it's uvs:
v3.setUv("uva_textz",Point2D(0,1))
grupo.refVertex(v3)

v4 = EggVertex()
v4.setPos(Point3D(horiz_a[i+4].x,horiz_a[i+4].y,horiz_a[i+4].z))
#set its normal:
v4.setNormal(myNormalize(Vec3(2*horiz_a[i+4].x-1, 2*horiz_a[i+4].y-1, 2*horiz_a[i+4].z-1)))
#set it's uvs:
v4.setUv("uva_textz",Point2D(0,0))
grupo.refVertex(v4)

#back-face:
poly.setBfaceFlag(True)

#fourth face:
poly = EggPolygon()
v = EggVertex()
v.setPos(Point3D(horiz_a[i+7].x,horiz_a[i+7].y,horiz_a[i+7].z))
#set its normal:
v.setNormal(myNormalize(Vec3(2*horiz_a[i+7].x-1, 2*horiz_a[i+7].y-1, 2*horiz_a[i+7].z-1)))
#set it's uvs:
v.setUv("uva_textz",Point2D(1,0))
grupo.refVertex(v)

v2 = EggVertex()
v2.setPos(Point3D(horiz_a[i+3].x,horiz_a[i+3].y,horiz_a[i+3].z))
#set its normal:
v2.setNormal(myNormalize(Vec3(2*horiz_a[i+3].x-1, 2*horiz_a[i+3].y-1, 2*horiz_a[i+3].z-1)))
#set it's uvs:
v2.setUv("uva_textz",Point2D(1,1))
grupo.refVertex(v2)

v3 = EggVertex()
v3.setPos(Point3D(horiz_a[i+1].x,horiz_a[i+1].y,horiz_a[i+1].z))
#set its normal:
v3.setNormal(myNormalize(Vec3(2*horiz_a[i+1].x-1, 2*horiz_a[i+1].y-1, 2*horiz_a[i+1].z-1)))
#set it's uvs:
v3.setUv("uva_textz",Point2D(0,1))
grupo.refVertex(v3)

v4 = EggVertex()
v4.setPos(Point3D(horiz_a[i+5].x,horiz_a[i+5].y,horiz_a[i+5].z))
#set its normal:
v4.setNormal(myNormalize(Vec3(2*horiz_a[i+5].x-1, 2*horiz_a[i+5].y-1, 2*horiz_a[i+5].z-1)))
#set it's uvs:
v4.setUv("uva_textz",Point2D(0,0))
grupo.refVertex(v4)

#back-face:
poly.setBfaceFlag(True)

#fifth face:
poly = EggPolygon()
v = EggVertex()
v.setPos(Point3D(horiz_a[i+5].x,horiz_a[i+5].y,horiz_a[i+5].z))
#set its normal:
v.setNormal(myNormalize(Vec3(2*horiz_a[i+5].x-1, 2*horiz_a[i+5].y-1, 2*horiz_a[i+5].z-1)))
#set it's uvs:
v.setUv("uva_textz",Point2D(1,0))
grupo.refVertex(v)

v2 = EggVertex()
v2.setPos(Point3D(horiz_a[i+4].x,horiz_a[i+4].y,horiz_a[i+4].z))
#set its normal:
v2.setNormal(myNormalize(Vec3(2*horiz_a[i+4].x-1, 2*horiz_a[i+4].y-1, 2*horiz_a[i+4].z-1)))
#set it's uvs:
v2.setUv("uva_textz",Point2D(1,1))
grupo.refVertex(v2)

v3 = EggVertex()
v3.setPos(Point3D(horiz_a[i].x,horiz_a[i].y,horiz_a[i].z))
#set its normal:
v3.setNormal(myNormalize(Vec3(2*horiz_a[i].x-1, 2*horiz_a[i].y-1, 2*horiz_a[i].z-1)))
#set it's uvs:
v3.setUv("uva_textz",Point2D(0,1))
grupo.refVertex(v3)

v4 = EggVertex()
v4.setPos(Point3D(horiz_a[i+1].x,horiz_a[i+1].y,horiz_a[i+1].z))
#set its normal:
v4.setNormal(myNormalize(Vec3(2*horiz_a[i+1].x-1, 2*horiz_a[i+1].y-1, 2*horiz_a[i+1].z-1)))
#set it's uvs:
v4.setUv("uva_textz",Point2D(0,0))
grupo.refVertex(v4)

#back-face:
poly.setBfaceFlag(True)

#sixth face:
poly = EggPolygon()
v = EggVertex()
v.setPos(Point3D(horiz_a[i+7].x,horiz_a[i+7].y,horiz_a[i+7].z))
#set its normal:
v.setNormal(myNormalize(Vec3(2*horiz_a[i+7].x-1, 2*horiz_a[i+7].y-1, 2*horiz_a[i+7].z-1)))
#set it's uvs:
v.setUv("uva_textz",Point2D(1,0))
grupo.refVertex(v)

v2 = EggVertex()
v2.setPos(Point3D(horiz_a[i+6].x,horiz_a[i+6].y,horiz_a[i+6].z))
#set its normal:
v2.setNormal(myNormalize(Vec3(2*horiz_a[i+6].x-1, 2*horiz_a[i+6].y-1, 2*horiz_a[i+6].z-1)))
#set it's uvs:
v2.setUv("uva_textz",Point2D(1,1))
grupo.refVertex(v2)

v3 = EggVertex()
v3.setPos(Point3D(horiz_a[i+2].x,horiz_a[i+2].y,horiz_a[i+2].z))
#set its normal:
v3.setNormal(myNormalize(Vec3(2*horiz_a[i+2].x-1, 2*horiz_a[i+2].y-1, 2*horiz_a[i+2].z-1)))
#set it's uvs:
v3.setUv("uva_textz",Point2D(0,1))
grupo.refVertex(v3)

v4 = EggVertex()
v4.setPos(Point3D(horiz_a[i+3].x,horiz_a[i+3].y,horiz_a[i+3].z))
#set its normal:
v4.setNormal(myNormalize(Vec3(2*horiz_a[i+3].x-1, 2*horiz_a[i+3].y-1, 2*horiz_a[i+3].z-1)))
#set it's uvs:
v4.setUv("uva_textz",Point2D(0,0))
grupo.refVertex(v4)

#back-face:
poly.setBfaceFlag(True)
#grupo.applyTexmats()
#some transform tests:
transformz=EggTransform()

mat=transformz.getTransform3d()
#print "MATRIX: ",mat
vp.transform(mat)

data.writeEgg(Filename("boxi_t.egg"))

makeBox()
run()``````

All I have left to do is: fix this texture issue, do joints to make an actor file, write animation files out.
The above code writes a cube out to disk for the purposes of confirming some things: normals, groups and transforms.

To the question, how would I apply a texture map to this geometry I am writing out, and subsequently, how would I manipulate the scale, rotation and offset of said texture map? I’ve looked at the egg library api and haven’t found much documentation regarding this.

Thanks.

Firstly, if you look in the API documentation for EggTexture, you’ll see that it inherits from EggTransform, which gives it all the transformation methods you need such as addScale2d and addTranslate2d, etc.

As for applying the texture to the geometry, you can do this with poly.setTexture(textz).

Thanks, that perfectly worked for me.