Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从对象面创建collada文件';顶点信息?_Python_Collada_Normals_Vertices_3d Modelling - Fatal编程技术网

Python 如何从对象面创建collada文件';顶点信息?

Python 如何从对象面创建collada文件';顶点信息?,python,collada,normals,vertices,3d-modelling,Python,Collada,Normals,Vertices,3d Modelling,我有一个项目要求我以.dae Collada格式导出模型。我正在努力想办法做到这一点。我一直在尝试使用pyCollada来实现这一点,但我在3D建模方面的经验有限,文件结构让我感到困惑。为什么要指定“法线_浮动”数组来构建多边形。顶点本身还不够吗 我有对象每个面的所有顶点,需要将数据导出为collada格式吗?因为每个面都是二维的,有没有一种简单的方法可以做到这一点?是否有一种算法可以简单地将顶点输入其中,以生成对象的适当面?任何帮助都将不胜感激 此外,我目前有一个在openGL中绘制对象的算法

我有一个项目要求我以.dae Collada格式导出模型。我正在努力想办法做到这一点。我一直在尝试使用pyCollada来实现这一点,但我在3D建模方面的经验有限,文件结构让我感到困惑。为什么要指定“法线_浮动”数组来构建多边形。顶点本身还不够吗

我有对象每个面的所有顶点,需要将数据导出为collada格式吗?因为每个面都是二维的,有没有一种简单的方法可以做到这一点?是否有一种算法可以简单地将顶点输入其中,以生成对象的适当面?任何帮助都将不胜感激

此外,我目前有一个在openGL中绘制对象的算法。在生成导出文件时,有没有一种方法可以重用用于此目的的代码

更新这是我试图遵循的创建对象的教程:


显然,您实际上可以在没有法线的情况下计算它,但是文档不清楚。

在self中为这一行定义的
layerdef=self.layerdef
在哪里。您还可以对上述代码的作用添加一些注释吗?:)
#Allows the laminate to get exported as a DAE.
def toDAE(self):
    """
    Exports the current lamiante to a DAE file format
    """
    import collada
    mesh = collada.Collada()
    layerdef = self.layerdef
    nodes = [] # Each node of the mesh scene. Typically one per layer.
    for layer in layerdef.layers:
        layer_thickness = layer.thickness    
        shapes = self.geoms[layer]
        zvalue = layerdef.z_values[layer]        
        height = float(zvalue) #* 100 #* 
        if (len(shapes) == 0) : #In case there are no shapes.
            continue
        for s in shapes:
            geom = self.createDAEFromShape(s, height, mesh, layer_thickness)
            mesh.geometries.append(geom) 
            effect = collada.material.Effect("effect", [], "phone", diffuse=(1,0,0), specular=(0,1,0))
            mat = collada.material.Material("material", "mymaterial" + str(s.id), effect)    
            matnode = collada.scene.MaterialNode("materialref" + str(s.id), mat, inputs=[])
            mesh.effects.append(effect)
            mesh.materials.append(mat)
            geomnode = collada.scene.GeometryNode(geom, [matnode])
            node = collada.scene.Node("node" + str(s.id), children=[geomnode])    
            nodes.append(node)
    myscene = collada.scene.Scene("myscene", nodes)
    mesh.scenes.append(myscene)
    mesh.scene = myscene
    filename = popupcad.exportdir + os.path.sep +  str(self.id) + '.dae' # 
    mesh.write(filename)


def createDAEFromShape(self, s, layer_num, mesh, thickness): #TODO Move this method into the shape class.
    import collada
    vertices = s.extrudeVertices(thickness, z0=layer_num)

    #This scales the verticies properly. So that they are in millimeters.
    vert_floats = [float(x)/(popupcad.SI_length_scaling) for x in vertices] 
    vert_src_name = str(self.id) + '|' + str(s.id) + "-array"
    vert_src = collada.source.FloatSource(vert_src_name, numpy.array(vert_floats), ('X', 'Y', 'Z'))
    geom = collada.geometry.Geometry(mesh, "geometry-" + str(s.id), str(self.id), [vert_src])
    input_list = collada.source.InputList()
    input_list.addInput(0, 'VERTEX', "#" + vert_src_name)
    indices = numpy.array(range(0,(len(vertices) // 3)));    
    triset = geom.createTriangleSet(indices, input_list, "materialref" + str(s.id))
    triset.generateNormals()    
    geom.primitives.append(triset)
    return geom