Changeset 356
- Timestamp:
- 11/04/02 15:46:23 (6 years ago)
- Files:
-
- trunk/RBRapier/RBRapier/Formats/Lightwave/MeshedObject.py (modified) (7 diffs)
- trunk/RBRapier/RBRapier/Tools/Geometry/Analysis/TriangleMesh.py (modified) (5 diffs)
- trunk/RBRapier/RBRapier/Tools/Projections.py (modified) (2 diffs)
- trunk/RBRapier/RBRapier/Tools/Quaternion.py (modified) (1 diff)
- trunk/RBRapier/RBRapier/Tools/Transformations.py (modified) (9 diffs)
- trunk/RBRapier/RBRapier/Tools/Vector.py (modified) (2 diffs)
- trunk/RBRapier/demo/Lightwave (added)
- trunk/RBRapier/demo/Lightwave/data (added)
- trunk/RBRapier/demo/Lightwave/data/ki162a.lwo (added)
- trunk/RBRapier/demo/Lightwave/scene.py (added)
- trunk/RBRapier/demo/Lightwave/simple.py (added)
- trunk/RBRapier/demo/Lightwave/simple.skin (added)
- trunk/RBRapier/demo/Wavefront/scene.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBRapier/RBRapier/Formats/Lightwave/MeshedObject.py
r354 r356 27 27 28 28 import weakref 29 30 29 import Loader 30 import Numeric 31 31 32 32 from RBRapier.Tools.Geometry.Analysis import TriangleLister … … 105 105 106 106 result.SetVertices(self.Vertices) 107 result.SetNormals(self.Normals) 107 108 108 109 if self.SurfaceGroups: … … 125 126 elif optimizemesh == 0: 126 127 self.SimpleMesh() 128 127 129 if optimizetraversal > 0: 128 130 self.OptimizeTraversals(optimizetraversal) … … 135 137 136 138 self.Name = FileInFormat.name 137 self.Vertices = obj.Vertices and VertexArrays.VertexArray(obj.Vertices) or None 139 self.Vertices = VertexArrays.VertexArray(obj.Vertices) 140 Normals = Numeric.zeros(self.Vertices.data.shape, self.Vertices.data.typecode()) 141 self.Normals = VertexArrays.NormalArray(Normals) 142 143 self.NormalDivide = Numeric.zeros(self.Vertices.data.shape[0], Numeric.UInt16) 138 144 self.SurfaceGroups = obj.Surfaces.values() 139 145 … … 162 168 v0,v1 = FaceTraversal[:2] 163 169 for v2 in FaceTraversal[2:]: 164 mesh.AddFace(v0,v1,v2) 170 face = mesh.AddFace(v0,v1,v2) 171 if face: 172 normal = face.CalculateNormal(self.Vertices.data) 173 self.Normals.data[v0] += normal 174 self.NormalDivide[v0] += 1 175 self.Normals.data[v1] += normal 176 self.NormalDivide[v1] += 1 177 self.Normals.data[v2] += normal 178 self.NormalDivide[v2] += 1 179 else: 180 assert v0==v1 or v1==v2 or v2==v0 165 181 v1 = v2 182 166 183 if __debug__: 167 184 print '%-20s[%6d]: ' % (Group.Name, len(mesh.Faces)*3), … … 182 199 Group.Traversals = TraversalMaker(mesh) 183 200 201 for data, divisor in zip(self.Normals.data, self.NormalDivide): 202 if divisor: data = data/float(divisor) 203 else: print "Unreferenced index", data, divisor 204 del self.NormalDivide 205 184 206 def SimpleTraversals(self): 185 207 for Group in self.SurfaceGroups: … … 236 258 237 259 test = MeshedObjectBuilder() 238 obj = test.Build(open('data/ki162a.lwo', 'rb'), 0, 0)260 obj = test.Build(open('data/ki162a.lwo', 'rb'), 1, 0) 239 261 print "Test complete." 240 262 trunk/RBRapier/RBRapier/Tools/Geometry/Analysis/TriangleMesh.py
r345 r356 25 25 26 26 import weakref 27 from RBRapier.Tools.Vector import Vector3 27 28 28 29 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 102 103 raise KeyError, "Expected one vertex, but found none! (%r, %r, %r)" % (self.v, (pv0, pv1), result) 103 104 105 def CalculateNormal(self, VertexList, KeepNormal=0): 106 vectors = [Vector3(VertexList[v]) for v in self.v] 107 e01 = vectors[1] - vectors[0] 108 e02 = vectors[2] - vectors[0] 109 normal = e01.Cross3(e02).Normalize().asarray() 110 if KeepNormal: self.normal = normal 111 return normal 112 104 113 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 105 114 … … 128 137 129 138 class FaceMesh(FlyweightGroupObject): 139 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 140 #~ Constants / Variables / Etc. 141 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 142 143 WarnOnOddities = 0 144 145 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 146 #~ Public Methods 147 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 148 130 149 def __init__(self, FaceClass=Face): 131 150 FaceClassName = '%s&%s'%(self.__class__.__name__, FaceClass.__name__) … … 138 157 def AddFace(self, v0,v1,v2): 139 158 if v0 == v1 or v1 == v2 or v2 == v0: 140 #print "DEGENERATE face", (v0,v1,v2) 159 if self.WarnOnOddities: 160 print "DEGENERATE face", (v0,v1,v2) 141 161 return None 142 162 else: … … 194 214 195 215 edge.Faces.append(face) 196 #if len(edge.Faces) > 2: 197 # print "ABNORMAL Edge:", edge, edge.Faces 216 if self.WarnOnOddities: 217 if len(edge.Faces) > 2: 218 print "ABNORMAL Edge:", edge, edge.Faces 198 219 return edge 199 220 200 221 def AddFace(self, v0,v1,v2): 201 222 if v0 == v1 or v1 == v2 or v2 == v0: 202 #print "DEGENERATE face", (v0,v1,v2) 223 if self.WarnOnOddities: 224 print "DEGENERATE face", (v0,v1,v2) 203 225 return None 204 226 else: trunk/RBRapier/RBRapier/Tools/Projections.py
r337 r356 154 154 [0., 0., -2./deprojh, zoff], 155 155 [0., 0., 0., 1.]], 156 Numeric.Float )156 Numeric.Float32) 157 157 return result 158 158 … … 256 256 [0., 0., -zoff, ugly], 257 257 [0., 0., -1., 0.]], 258 Numeric.Float )258 Numeric.Float32) 259 259 return result 260 260 trunk/RBRapier/RBRapier/Tools/Quaternion.py
r340 r356 109 109 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 110 110 111 NumericType = Numeric.Float 111 NumericType = Numeric.Float32 112 112 113 113 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBRapier/RBRapier/Tools/Transformations.py
r337 r356 136 136 def asArray4x4(self): 137 137 """Returns the transformation in 4x4 Numeric array form""" 138 r = Numeric.identity(4, Numeric.Float )138 r = Numeric.identity(4, Numeric.Float32) 139 139 for xform in self.collection: 140 140 r = Numeric.dot(r, xform.asArray4x4()) … … 169 169 170 170 def __init__(self, matrix=None): 171 if matrix: self.matrix = Numeric.asarray(matrix, Numeric.Float )172 else: self.matrix = Numeric.identity(4, Numeric.Float )171 if matrix: self.matrix = Numeric.asarray(matrix, Numeric.Float32) 172 else: self.matrix = Numeric.identity(4, Numeric.Float32) 173 173 assert self.matrix.shape == (4,4) 174 174 … … 208 208 209 209 def asArray4x4(self): 210 return Numeric.identity(4, Numeric.Float )210 return Numeric.identity(4, Numeric.Float32) 211 211 212 212 def asInverse4x4(self): 213 return Numeric.identity(4, Numeric.Float )213 return Numeric.identity(4, Numeric.Float32) 214 214 215 215 def Inverse(self): … … 244 244 245 245 def asArray4x4(self): 246 result = Numeric.identity(4, Numeric.Float )246 result = Numeric.identity(4, Numeric.Float32) 247 247 result[:, 3] = self.Direction 248 248 return result 249 249 250 250 def asInverse4x4(self): 251 result = Numeric.identity(4, Numeric.Float )251 result = Numeric.identity(4, Numeric.Float32) 252 252 result[:, 3] = -self.Direction 253 253 return result … … 289 289 290 290 def asArray4x4(self): 291 result = Numeric.identity(4, Numeric.Float )291 result = Numeric.identity(4, Numeric.Float32) 292 292 for idx in range(4): result[idx,idx] = self.Scale[idx] 293 293 return result 294 294 295 295 def asInverse4x4(self): 296 result = Numeric.identity(4, Numeric.Float )296 result = Numeric.identity(4, Numeric.Float32) 297 297 for idx in range(4): result[idx,idx] = 1./self.Scale[idx] 298 298 return result … … 377 377 u = self.Axis[:-1] 378 378 uut = Numeric.outerproduct(u, u) 379 M = Numeric.identity(3, Numeric.Float ) - uut380 S = Numeric.asarray([[0., -u[2], u[1]], [u[2], 0., -u[0]], [-u[1], u[0], 0.]], Numeric.Float )379 M = Numeric.identity(3, Numeric.Float32) - uut 380 S = Numeric.asarray([[0., -u[2], u[1]], [u[2], 0., -u[0]], [-u[1], u[0], 0.]], Numeric.Float32) 381 381 radians = self.Radians 382 382 R = uut + math.cos(radians) * M + math.sin(radians) * S 383 result = Numeric.identity(4, Numeric.Float )383 result = Numeric.identity(4, Numeric.Float32) 384 384 result[:3,:3] = R 385 385 return result … … 432 432 U_ = S.Cross3(L) 433 433 434 result = Numeric.identity(4, Numeric.Float )434 result = Numeric.identity(4, Numeric.Float32) 435 435 result[0,:-1] = S 436 436 result[1,:-1] = U_ 437 437 result[2,:-1] = -L 438 xlate = Numeric.identity(4, Numeric.Float )438 xlate = Numeric.identity(4, Numeric.Float32) 439 439 xlate[:-1,3] = -E 440 440 return Numeric.dot(result, xlate) … … 622 622 [0, 0, Zs, Zt], 623 623 [0, 0, 0, 1]], 624 Numeric.Float )624 Numeric.Float32) 625 625 return result 626 626 … … 634 634 [0, 0, Zs, Zt], 635 635 [0, 0, 0, 1]], 636 Numeric.Float )636 Numeric.Float32) 637 637 return result 638 638 trunk/RBRapier/RBRapier/Tools/Vector.py
r340 r356 133 133 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 134 134 135 NumericType = Numeric.Float 135 NumericType = Numeric.Float32 136 136 Default = Numeric.asarray((0.,0.,0.), NumericType) 137 137 … … 377 377 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 378 378 379 NumericType = Numeric.Float 379 NumericType = Numeric.Float32 380 380 Default = Numeric.asarray((0.,0.,0.,1.), NumericType) 381 381 trunk/RBRapier/demo/Wavefront/scene.py
r351 r356 59 59 self.Sequence.AddElement(self.Viewport, -2) 60 60 61 self.GeoObj = self.WavefrontOBJ('data/oldtree.obj' )61 self.GeoObj = self.WavefrontOBJ('data/oldtree.obj', 0, 0) 62 62 #self.GeoObj = self.WavefrontOBJ('data/x29.obj') 63 63
