| 1 |
#!/usr/bin/env python |
|---|
| 2 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 3 |
##~ License |
|---|
| 4 |
##~ |
|---|
| 5 |
##- The RuneBlade Foundation library is intended to ease some |
|---|
| 6 |
##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.) |
|---|
| 7 |
##- applications, while providing the flexibility to modularly change the |
|---|
| 8 |
##- architecture. Enjoy. |
|---|
| 9 |
##~ |
|---|
| 10 |
##~ Copyright (C) 2002 TechGame Networks, LLC. |
|---|
| 11 |
##~ |
|---|
| 12 |
##~ This library is free software; you can redistribute it and/or |
|---|
| 13 |
##~ modify it under the terms of the BSD style License as found in the |
|---|
| 14 |
##~ LICENSE file included with this distribution. |
|---|
| 15 |
##~ |
|---|
| 16 |
##~ TechGame Networks, LLC can be reached at: |
|---|
| 17 |
##~ 3578 E. Hartsel Drive #211 |
|---|
| 18 |
##~ Colorado Springs, Colorado, USA, 80920 |
|---|
| 19 |
##~ |
|---|
| 20 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 21 |
|
|---|
| 22 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 23 |
#~ Imports |
|---|
| 24 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 25 |
|
|---|
| 26 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 27 |
#~ Definitions |
|---|
| 28 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 29 |
|
|---|
| 30 |
def RemapOffsetIndices(obj): |
|---|
| 31 |
# Offset Indices Detected: Must remap so that all indices line up... duplicating data where necessary |
|---|
| 32 |
Vertices, obj.Vertices = obj.Vertices, [] |
|---|
| 33 |
Normals, obj.Normals = obj.Normals, [] |
|---|
| 34 |
TexCoords, obj.TexCoords = obj.TexCoords, [] |
|---|
| 35 |
Mapping = {} |
|---|
| 36 |
for Group in obj.Groups: |
|---|
| 37 |
for FaceTraversal in Group.Faces: |
|---|
| 38 |
for idx in xrange(len(FaceTraversal)): |
|---|
| 39 |
VTN = FaceTraversal[idx] |
|---|
| 40 |
# Have we already seen this tuple? |
|---|
| 41 |
newVTN = Mapping.get(VTN, None) |
|---|
| 42 |
if newVTN is None: |
|---|
| 43 |
# If not, lets make a new index |
|---|
| 44 |
newVTN = Mapping.setdefault(VTN, len(Mapping)) |
|---|
| 45 |
# and copy the appropriate data |
|---|
| 46 |
if Vertices: obj.Vertices.append(Vertices[VTN[0]]) |
|---|
| 47 |
if TexCoords: obj.TexCoords.append(TexCoords[VTN[1]]) |
|---|
| 48 |
if Normals: obj.Normals.append(Normals[VTN[2]]) |
|---|
| 49 |
# Copy the remapped VTN to the face traversal |
|---|
| 50 |
FaceTraversal[idx] = (newVTN,) |
|---|