def exportMeshes(selectedArmature, selectedMeshes, modProtected): xpsMeshes = [] if modProtected: xpsMesh = xps_types.XpsMesh('p_dummyobject_0_0_0', [], [], [], 0) xpsMeshes.append(xpsMesh) for mesh in selectedMeshes: print('Exporting Mesh:', mesh.name) meshName = makeNamesFromMesh(mesh) # meshName = makeNamesFromMaterials(mesh) meshTextures = getXpsMatTextures(mesh) meshVerts, meshFaces = getXpsVertices(selectedArmature, mesh) meshUvCount = len(mesh.data.uv_layers) materialsCount = len(mesh.data.materials) if (materialsCount > 0): for idx in range(materialsCount): xpsMesh = xps_types.XpsMesh(meshName[idx], meshTextures[idx], meshVerts[idx], meshFaces[idx], meshUvCount) xpsMeshes.append(xpsMesh) else: dummyTexture = [xps_types.XpsTexture(0, 'dummy.png', 0)] xpsMesh = xps_types.XpsMesh(meshName[0], dummyTexture, meshVerts[0], meshFaces[0], meshUvCount) xpsMeshes.append(xpsMesh) return xpsMeshes
def readMeshes(file, xpsHeader, hasBones): meshes = [] meshCount = bin_ops.readUInt32(file) hasHeader = bool(xpsHeader) hasTangent = False if hasHeader: hasTangent = hasTangentHeader(xpsHeader) for meshId in range(meshCount): # Name meshName = readFilesString(file) if not meshName: meshName = 'unnamed' # print('Mesh Name:', meshName) # uv Count uvLayerCount = bin_ops.readUInt32(file) # Textures textures = [] textureCount = bin_ops.readUInt32(file) for texId in range(textureCount): textureFile = ntpath.basename(readFilesString(file)) # print('Texture file', textureFile) uvLayerId = bin_ops.readUInt32(file) xpsTexture = xps_types.XpsTexture(texId, textureFile, uvLayerId) textures.append(xpsTexture) # Vertices vertex = [] vertexCount = bin_ops.readUInt32(file) for vertexId in range(vertexCount): coord = readXYZ(file) normal = readXYZ(file) vertexColor = readVertexColor(file) uvs = [] for uvLayerId in range(uvLayerCount): uvVert = readUvVert(file) uvs.append(uvVert) if not hasHeader or hasTangent: tangent = read4Float(file) boneWeights = [] if hasBones: # if cero bones dont have weights to read boneIdx = read4Int16(file) boneWeight = read4Float(file) for idx in range(len(boneIdx)): boneWeights.append( xps_types.BoneWeight(boneIdx[idx], boneWeight[idx])) xpsVertex = xps_types.XpsVertex(vertexId, coord, normal, vertexColor, uvs, boneWeights) vertex.append(xpsVertex) # Faces faces = [] triCount = bin_ops.readUInt32(file) for i in range(triCount): triIdxs = readTriIdxs(file) faces.append(triIdxs) xpsMesh = xps_types.XpsMesh(meshName, textures, vertex, faces, uvLayerCount) meshes.append(xpsMesh) return meshes
def readMeshes(file, hasBones): meshes = [] meshCount = ascii_ops.readInt(file) for meshId in range(meshCount): # Name meshName = ascii_ops.readString(file) if not meshName: meshName = 'xxx' # print('Mesh Name:', meshName) # uv Count uvLayerCount = ascii_ops.readInt(file) # Textures textures = [] textureCount = ascii_ops.readInt(file) for texId in range(textureCount): textureFile = ntpath.basename(ascii_ops.readString(file)) # print('Texture file', textureFile) uvLayerId = ascii_ops.readInt(file) xpsTexture = xps_types.XpsTexture(texId, textureFile, uvLayerId) textures.append(xpsTexture) # Vertices vertex = [] vertexCount = ascii_ops.readInt(file) for vertexId in range(vertexCount): coord = readXYZ(file) normal = readXYZ(file) vertexColor = read4Int(file) uvs = [] for uvLayerId in range(uvLayerCount): uvVert = readUvVert(file) uvs.append(uvVert) # if ???? # tangent???? # tangent = read4float(file) boneWeights = [] if hasBones: # if cero bones dont have weights to read boneIdx = readBoneId(file) boneWeight = readBoneWeight(file) for idx in range(len(boneIdx)): boneWeights.append( xps_types.BoneWeight(boneIdx[idx], boneWeight[idx])) xpsVertex = xps_types.XpsVertex(vertexId, coord, normal, vertexColor, uvs, boneWeights) vertex.append(xpsVertex) # Faces faces = [] triCount = ascii_ops.readInt(file) for i in range(triCount): triIdxs = readTriIdxs(file) faces.append(triIdxs) xpsMesh = xps_types.XpsMesh(meshName, textures, vertex, faces, uvLayerCount) meshes.append(xpsMesh) return meshes
def buildMeshes(): meshes = [] meshName = 'Mesh1' uvLayerCount = 1 # Textures textures = [] texId = 0 textureFile = 'textutefile1.png' uvLayerId = 0 xpsTexture = xps_types.XpsTexture(texId, textureFile, uvLayerId) textures.append(xpsTexture) texId = 1 textureFile = 'textutefile2.png' uvLayerId = 0 xpsTexture = xps_types.XpsTexture(texId, textureFile, uvLayerId) textures.append(xpsTexture) # Vertices vertex = [] # Vertex1 vertexId = 0 coord = (1, 0, 0) normal = (0, 0, 1) vertexColor = (255, 255, 255, 0) uvs = [] uvs.append((.2, .4)) boneWeights = (xps_types.BoneWeight(0, 0), xps_types.BoneWeight(0, 0), xps_types.BoneWeight(0, 0), xps_types.BoneWeight(0, 0)) xpsVertex = xps_types.XpsVertex(vertexId, coord, normal, vertexColor, uvs, boneWeights) # Vertex2 vertexId = 1 coord = (0, 1, 0) normal = (0, 1, 0) vertexColor = (255, 255, 255, 0) uvs = [] uvs.append((.3, .5)) boneWeights = (xps_types.BoneWeight(0, 0), xps_types.BoneWeight(0, 0), xps_types.BoneWeight(0, 0), xps_types.BoneWeight(0, 0)) xpsVertex = xps_types.XpsVertex(vertexId, coord, normal, vertexColor, uvs, boneWeights) vertex.append(xpsVertex) # Vertex3 vertexId = 2 coord = (0, 0, 1) normal = (1, 0, 0) vertexColor = (255, 255, 255, 0) uvs = [] uvs.append((.3, .9)) boneWeights = (xps_types.BoneWeight(0, 0), xps_types.BoneWeight(0, 0), xps_types.BoneWeight(0, 0), xps_types.BoneWeight(0, 0)) xpsVertex = xps_types.XpsVertex(vertexId, coord, normal, vertexColor, uvs, boneWeights) vertex.append(xpsVertex) faces = [] face = (0, 1, 2) faces.append(face) xpsMesh = xps_types.XpsMesh(meshName, textures, vertex, faces, uvLayerCount) meshes.append(xpsMesh) return meshes
def createJoinedMeshes(): meshPartRegex = re.compile('(!.*)*([\d]+nPart)*!') sortedMeshesList = sorted(xpsData.meshes, key=operator.attrgetter('name')) joinedMeshesNames = list( {meshPartRegex.sub('', mesh.name, 0) for mesh in sortedMeshesList}) joinedMeshesNames.sort() newMeshes = [] for joinedMeshName in joinedMeshesNames: # for each joinedMeshName generate a list of meshes to join meshesToJoin = [ mesh for mesh in sortedMeshesList if meshPartRegex.sub('', mesh.name, 0) == joinedMeshName ] totalVertexCount = 0 vertexCount = 0 meshCount = 0 meshName = None textures = None vertex = None faces = None uvLayerCount = None # new name for the unified mesh meshName = meshPartRegex.sub('', meshesToJoin[0].name, 0) # all the meshses share the same textures textures = meshesToJoin[0].textures # all the meshses share the uv layers count uvCount = meshesToJoin[0].uvCount # all the new joined mesh names vertex = [] faces = [] for mesh in meshesToJoin: vertexCount = 0 meshCount = meshCount + 1 if len(meshesToJoin ) > 1 or meshesToJoin[0] not in sortedMeshesList: # unify vertex for vert in mesh.vertices: vertexCount = vertexCount + 1 newVertice = xps_types.XpsVertex( vert.id + totalVertexCount, vert.co, vert.norm, vert.vColor, vert.uv, vert.boneWeights) vertex.append(newVertice) # unify faces for face in mesh.faces: newFace = [ face[0] + totalVertexCount, face[1] + totalVertexCount, face[2] + totalVertexCount ] faces.append(newFace) else: vertex = mesh.vertices faces = mesh.faces totalVertexCount = totalVertexCount + vertexCount # Creates the nuw unified mesh xpsMesh = xps_types.XpsMesh(meshName, textures, vertex, faces, uvCount) newMeshes.append(xpsMesh) return newMeshes