def testSaveVertsUV(self): a = pyngl.Obj() a.addVertex(pyngl.Vec3(2.00000, 0.00000, 0.000000)) a.addVertex(pyngl.Vec3(0.0000, 4.0000, 0.000000)) a.addVertex(pyngl.Vec3(-2.00000, 0.000000, 0.00000)) a.addUV(pyngl.Vec2(1.0, 0.0)) a.addUV(pyngl.Vec2(0.5, 1.0)) a.addUV(pyngl.Vec2(0.004399, 0.008916)) f = pyngl.Face() f.m_vert.push_back(0) f.m_vert.push_back(1) f.m_vert.push_back(2) f.m_uv.push_back(0) f.m_uv.push_back(1) f.m_uv.push_back(2) a.addFace(f) a.save('faceUV.obj') b = pyngl.Obj('faceUV.obj') face = b.getFaceList() self.assertEqual(face[0].m_vert[0], 0) self.assertEqual(face[0].m_vert[1], 1) self.assertEqual(face[0].m_vert[2], 2) verts = b.getVertexList() self.assertTrue(verts[0] == pyngl.Vec3(2.0, 0.0, 0.0)) self.assertTrue(verts[1] == pyngl.Vec3(0.0, 4.0, 0.0)) self.assertTrue(verts[2] == pyngl.Vec3(-2.0, 0.0, 0.0)) uv = b.getUVList() self.assertTrue(uv[0] == pyngl.Vec3(1.0, 0.0, 0.0)) self.assertTrue(uv[1] == pyngl.Vec3(0.5, 1.0, 0.0)) self.assertTrue(uv[2] == pyngl.Vec3(0.004399, 0.008916, 0.0)) os.remove('faceUV.obj')
def testAddUV2(self): a = pyngl.Obj() v = 0.0 for i in range(0, 20): a.addUV(pyngl.Vec2(v, v)) v = v + 1.0 uv = a.getUVList() v = 0.0 for i in range(0, 20): self.assertTrue(uv[i] == pyngl.Vec3(v, v, 0)) v += 1.0
def testCopyCtor(self): a = pyngl.Obj() a.addVertex(pyngl.Vec3(2.00000, 0.00000, 0.000000)) a.addVertex(pyngl.Vec3(0.0000, 4.0000, 0.000000)) a.addVertex(pyngl.Vec3(-2.00000, 0.000000, 0.00000)) a.addNormal(pyngl.Vec3(0.0, 0.0, 1.0)) a.addNormal(pyngl.Vec3(0.0, 0.0, 1.0)) a.addNormal(pyngl.Vec3(0.0, 0.0, 1.0)) a.addUV(pyngl.Vec2(1.0, 0.0)) a.addUV(pyngl.Vec2(0.5, 1.0)) a.addUV(pyngl.Vec2(0.004399, 0.008916)) f = pyngl.Face() f.m_vert.push_back(0) f.m_vert.push_back(1) f.m_vert.push_back(2) f.m_norm.push_back(0) f.m_norm.push_back(1) f.m_norm.push_back(2) f.m_uv.push_back(0) f.m_uv.push_back(1) f.m_uv.push_back(2) a.addFace(f) b = a face = b.getFaceList() self.assertEqual(face[0].m_vert[0], 0) self.assertEqual(face[0].m_vert[1], 1) self.assertEqual(face[0].m_vert[2], 2) verts = b.getVertexList() self.assertTrue(verts[0] == pyngl.Vec3(2.0, 0.0, 0.0)) self.assertTrue(verts[1] == pyngl.Vec3(0.0, 4.0, 0.0)) self.assertTrue(verts[2] == pyngl.Vec3(-2.0, 0.0, 0.0)) norm = b.getNormalList() self.assertTrue(norm[0] == pyngl.Vec3(0.0, 0.0, 1.0)) self.assertTrue(norm[1] == pyngl.Vec3(0.0, 0.0, 1.0)) self.assertTrue(norm[2] == pyngl.Vec3(0.0, 0.0, 1.0)) uv = b.getUVList() self.assertTrue(uv[0] == pyngl.Vec3(1.0, 0.0, 0.0)) self.assertTrue(uv[1] == pyngl.Vec3(0.5, 1.0, 0.0)) self.assertTrue(uv[2] == pyngl.Vec3(0.004399, 0.008916, 0.0))
def buildObj(self): a = pyngl.Obj() a.addVertex(pyngl.Vec3(2.00000, 0.00000, 0.000000)) a.addVertex(pyngl.Vec3(0.0000, 4.0000, 0.000000)) a.addVertex(pyngl.Vec3(-2.00000, 0.000000, 0.000000)) a.addUV(pyngl.Vec2(1.000000, 0.000000)) a.addUV(pyngl.Vec2(0.500000, 1.000000)) a.addUV(pyngl.Vec2(0.004399, 0.008916)) a.addNormal(pyngl.Vec3(0.000000, 0.000000, 1.000000)) a.addNormal(pyngl.Vec3(0.000000, 0.000000, 1.000000)) a.addNormal(pyngl.Vec3(0.000000, 0.000000, 1.000000)) f = pyngl.Face() # f 1/1/1 2/2/2 3/3/3 f.m_vert.push_back(0) f.m_vert.push_back(1) f.m_vert.push_back(2) f.m_uv.push_back(0) f.m_uv.push_back(1) f.m_uv.push_back(2) f.m_norm.push_back(0) f.m_norm.push_back(1) f.m_norm.push_back(2) a.addFace(f) return a
def testAssignOperator(self): test = pyngl.Vec2(1.0, 2.0) copy = test result = pyngl.Vec2(1.0, 2.0) self.assertEqual(test, result)
def testdefaultCtor(self): test = pyngl.Vec2() result = pyngl.Vec2(0.0, 0.0) self.assertEqual(test, result)
def testSubscipt(self): test = pyngl.Vec2(1, 2) self.assertAlmostEqual(test[0], 1.0) self.assertAlmostEqual(test[1], 2.0)
def testFloatCtor(self): test = pyngl.Vec2(1.0, 2.0) result = pyngl.Vec2(1.0, 2.0) self.assertEqual(test, result)
def testLengthSquared(self): a = pyngl.Vec2(22.0, 1.0) self.assertAlmostEqual(a.lengthSquared(), 485.0, delta=0.001)
def testLength(self): a = pyngl.Vec2(22.0, 1.0) self.assertAlmostEqual(a.length(), 22.022, delta=0.001)
def testNormalize(self): test = pyngl.Vec2(22.3, 0.5) test.normalize() result = pyngl.Vec2(0.9997, 0.0224) self.assertTrue(test == result) self.assertEqual(test, result)
def testNull(self): test = pyngl.Vec2(1, 2) test.null() self.assertTrue(test == pyngl.Vec2.zero())
def testDotProduct(self): a = pyngl.Vec2(1.0, 2.0) b = pyngl.Vec2(4.0, 5.0) self.assertEqual(a.dot(b), 14.0)