gpt4 book ai didi

python - 如何让 PyC​​ollada 向同一场景输出多个网格?

转载 作者:太空宇宙 更新时间:2023-11-03 17:38:51 24 4
gpt4 key购买 nike

所以我使用 pyCollada 尝试将多个网格导出到同一场景。唉,每当我尝试这样做时,我只能看到已加载的网格之一。创建文件时我是否做错了什么?如果我将它们分离到自己的文件中,每个单独的网格都会完美渲染,但当我尝试将它们输出到同一文件时,它们会失败。我查看了 API,但文档非常有限。任何帮助将不胜感激。

我的代码如下所示。

# -*- coding: utf-8 -*-
"""
Created on Fri Jun 12 14:43:05 2015

@author: skylion
"""

# -*- coding: utf-8 -*-

"""

Created on Thu Jun 11 11:01:48 2015


@author: danaukes

"""


import sys
import popupcad_deprecated
import popupcad_manufacturing_plugins
import popupcad

from popupcad.filetypes.design import Design

import PySide.QtGui as qg


#Draws Collada stuff
from collada import *
import numpy

geom_index = 0;

def exportBodyToMesh(output):
# csg = output.csg
generic = output.generic_laminate()
# layers = generic.layers()
layerdef = d.return_layer_definition()
layerdef.refreshzvalues()
# layers = layerdef.layers
mesh = Collada()
nodes = []
for layer in layerdef.layers:
shapes = generic.geoms[layer]#TODO Add it in for other shapes
zvalue = layerdef.zvalue[layer]
height = zvalue * 1/ popupcad.internal_argument_scaling
print zvalue
if (len(shapes) == 0) : #In case there are no shapes.
print "No shapes skipping"
continue
print shapes
for s in shapes:
geom = createMeshFromShape(s, height, mesh)
mesh.geometries.append(geom)
effect = material.Effect("effect" + str(geom_index), [], "phone", diffuse=(1,0,0), specular=(0,1,0))
mat = material.Material("material" + str(geom_index), "mymaterial", effect)
matnode = scene.MaterialNode("materialref" + str(geom_index), mat, inputs=[])
mesh.effects.append(effect)
mesh.materials.append(mat)
geomnode = scene.GeometryNode(geom, [matnode])
node = scene.Node("node" + str(geom_index), children=[geomnode])
nodes.append(node)
print nodes
myscene = scene.Scene("myscene", nodes)
mesh.scenes.append(myscene)
mesh.scene = myscene
# layer_num = layer_num + 1 #Add the layer thicknes instead of simply + 1
filename = str(output) + '.dae'
mesh.write(filename)
#TODO Add handling in case rigid body has already been selected.
print filename + " has been saved"


def createMeshFromShape(s,layer_num, mesh):
s.exteriorpoints()
a = s.triangles3()
vertices = []
global geom_index
for coord in a:
for dec in coord:
vertices.append(dec[0]) #x-axis
vertices.append(dec[1]) #y-axis
vertices.append(layer_num ) #z-axi

#This scales the verticies properly.
vert_floats = [x/popupcad.internal_argument_scaling for x in vertices]
vert_src = source.FloatSource("cubeverts-array" + str(geom_index), numpy.array(vert_floats), ('X', 'Y', 'Z'))
geom = geometry.Geometry(mesh, "geometry" + str(geom_index), "mycube", [vert_src])
input_list = source.InputList()
input_list.addInput(0, 'VERTEX', "#cubeverts-array" + str(geom_index))
indices = numpy.array(range(0,(len(vertices) / 3)));
triset = geom.createTriangleSet(indices, input_list, "materialref")
geom_index += 1
triset.generateNormals()
geom.primitives.append(triset)
return geom

#Start of actual script
print sys.argv

app = qg.QApplication('exporter.py')

d = Design.open()

print "Loading..."

d.reprocessoperations()

operation = d.operations[3] #Identify bodies

for output in operation.output:
exportBodyToMesh(output)

print "All objects printed"

#sys.exit(app.exec_())

最佳答案

将几何图形添加到场景的代码位于内部循环之外。您只需将最后一个几何体添加到场景中,而不是全部几何体。您应该创建多个 GeometryNode 并将它们全部添加到 Scene 中。

关于python - 如何让 PyC​​ollada 向同一场景输出多个网格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30849843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com