Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.3 KiB

  1. # Export from maya directly into simple vertex / index buffer for direct rendering
  2. # Usage: just run the script below on a selected mesh object. it'll print vertex and index buffers
  3. import sys
  4. import math
  5. import os
  6. import StringIO
  7. import maya.OpenMaya as OpenMaya
  8. import maya.OpenMayaMPx as OpenMayaMPx
  9. selList = OpenMaya.MSelectionList()
  10. OpenMaya.MGlobal.getActiveSelectionList(selList)
  11. selListIter = OpenMaya.MItSelectionList(selList)
  12. listVertices = []
  13. listFaces = []
  14. while not selListIter.isDone():
  15. dagPath = OpenMaya.MDagPath()
  16. component = OpenMaya.MObject()
  17. selListIter.getDagPath(dagPath, component)
  18. rot = OpenMaya.MQuaternion()
  19. dagTransform = dagPath.transform()
  20. if( dagTransform.apiType() == OpenMaya.MFn.kTransform ):
  21. xformFn = OpenMaya.MFnTransform(dagTransform)
  22. xform = xformFn.transformation().asRotateMatrix()
  23. xformFn.getRotation( rot )
  24. else:
  25. xform = OpenMaya.MMatrix()
  26. xform.setToIdentity()
  27. dagPath.extendToShape()
  28. if (dagPath.apiType() == OpenMaya.MFn.kMesh):
  29. mesh = dagPath.node()
  30. meshFn = OpenMaya.MFnMesh(mesh)
  31. vertIter = OpenMaya.MItMeshVertex( dagPath, component )
  32. print "// ", vertIter.count(), " verts in ", dagPath.partialPathName()
  33. print "ErrorRenderLoop::Vertex_t g_verts_%s[%d] = {" % (dagPath.partialPathName(), vertIter.count())
  34. while not vertIter.isDone():
  35. vertPos = OpenMaya.MVector(vertIter.position()).rotateBy(rot)
  36. vertColor = OpenMaya.MColor(1,1,1,1)
  37. vertNormal = OpenMaya.MVector()
  38. vertIter.getNormal( vertNormal )
  39. if( vertIter.hasColor() ):
  40. vertIter.getColor( vertColor )
  41. vertNormal = vertNormal.rotateBy(rot)
  42. print "{%.3f,%.3f,%.3f, %.3f,%.3f,%.3f, 0x%02X%02X%02X%02X }," % (vertPos.x,vertPos.y,vertPos.z, vertNormal.x, vertNormal.y, vertNormal.z, vertColor.r*255, vertColor.g*255,vertColor.b*255, vertColor.a*255 )
  43. vertIter.next()
  44. print "};"
  45. faceIter = OpenMaya.MItMeshPolygon(dagPath,component)
  46. print "// ", faceIter.count(), " triangles"
  47. print "uint16_t g_tris_%s[%d][3] = {" % ( dagPath.partialPathName(), faceIter.count() )
  48. faceCount = 0
  49. while not faceIter.isDone():
  50. faceVerts = OpenMaya.MIntArray()
  51. faceIter.getVertices( faceVerts )
  52. print ("" if faceCount == 0 else ", "), "{ ", ", ".join( str(x) for x in faceVerts ), " }"
  53. faceCount = faceCount + 1
  54. faceIter.next()
  55. print "};"
  56. selListIter.next()