需要帮助了解 DAE 文件以及真正需要什么
我目前正在尝试将 3D 模型输出到 dae 文件。当前的问题是 Blender(和其他模型查看器)不会打开该文件。我没有从搅拌机中收到任何错误。我在网上关注了 dae 的例子,我想我已经拥有了所需的一切。我现在需要输出的只是面和顶点。以前,我将其输出到 obj 没有任何问题。
我不知道我是否错过了什么。
下面是我的代码输出的 dae 文件的示例。为了我们的理智,我从如下所示的输出中删除了 4000 个顶点和面。
<?xml version="1.0" encoding="UTF-8"?>
<COLLADA version="1.4.1">
<asset>
<contributor>
<author>Justin (JDOG) Barren</author>
<authoring_tool>RaxToDae File Ripper</authoring_tool>
</contributor>
<unit meter="1.000000"/>
<up_axis>Z_UP</up_axis>
</asset>
<library_geometries>
<geometry id="F1" name="allModel">
<mesh>
<source id="allModel-vertex-positions">
<float_array id="ID2-array" count="14442"> [ ...lots of numbers... ] </float_array>
<technique_common>
<accessor source="#ID2-array" count="4814" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="allModel-vertices">
<input semantic="POSITION" source="#allModel-vertex-positions">
</vertices>
<triangles count="4842">
<input semantic="VERTEX" offset="0" source="#allModel-vertices"/>
<p> [ ...lots of numbers... ] </p>
</triangles>
</mesh>
</geometry>
</library_geometries>
<scene>
<instance_visual_scene url="#Scene"/>
</scene>
</COLLADA>
这是我用 C++ 生成文件的代码。
void OutputHeader(ofstream& stream) {
stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
//stream << "<COLLADA xmlns=\"http://www.collada.org/2005/11/COLLADASchema\" version=\"1.4.1\">" << endl;
stream << "<COLLADA version=\"1.4.1\">" << endl;
stream << "\t<asset>" << endl;
stream << "\t\t<contributor>" << endl;
stream << "\t\t\t<author>Justin (JDOG) Barren</author>" << endl;
stream << "\t\t\t<authoring_tool>RaxToDae File Ripper</authoring_tool>" << endl;
stream << "\t\t</contributor>" << endl;
stream << "\t\t<unit meter=\"1.000000\"/>" << endl;
stream << "\t\t<up_axis>Z_UP</up_axis>" << endl;
stream << "\t</asset>" << endl;
}
void OutputVertsAndFaces(ofstream& stream, string modelName, int vertCount, int faceCount, vector <float> verts, vector <short> faces) {
stream << "\t<library_geometries>" << endl;
stream << "\t\t<geometry id=\"F1\" name=\"" << modelName << "\">" << endl;
stream << "\t\t\t<mesh>" << endl;
stream << "\t\t\t\t<source id=\"" << modelName << "-vertex-positions\">" << endl;
stream << "\t\t\t\t\t<float_array id=\"ID2-array\" count=\"" << vertCount << "\">" << endl; for (int i = 0; i < verts.size(); i++) stream << verts[i] << " "; stream << "</float_array>" << endl;
stream << "\t\t\t\t\t<technique_common>" << endl;
stream << "\t\t\t\t\t\t<accessor source=\"#ID2-array\" count=\"" << vertCount/3 << "\" stride=\"3\">" << endl;
stream << "\t\t\t\t\t\t\t<param name=\"X\" type=\"float\"/>" << endl;
stream << "\t\t\t\t\t\t\t<param name=\"Y\" type=\"float\"/>" << endl;
stream << "\t\t\t\t\t\t\t<param name=\"Z\" type=\"float\"/>" << endl;
stream << "\t\t\t\t\t\t</accessor>" << endl;
stream << "\t\t\t\t\t</technique_common>" << endl;
stream << "\t\t\t\t</source>" << endl;
stream << "\t\t\t\t<vertices id=\"" << modelName << "-vertices\">" << endl;
stream << "\t\t\t\t\t<input semantic=\"POSITION\" source=\"#" << modelName << "-vertex-positions\">" << endl;
stream << "\t\t\t\t</vertices>" << endl;
stream << "\t\t\t\t<triangles count=\"" << faceCount << "\">" << endl;
stream << "\t\t\t\t\t<input semantic=\"VERTEX\" offset=\"0\" source=\"#" << modelName << "-vertices\"/>" << endl;
stream << "\t\t\t\t\t<p>"; for (int i = 0; i < faces.size(); i++) stream << faces[i] << " "; stream << "</p>" << endl;
stream << "\t\t\t\t</triangles>" << endl;
stream << "\t\t\t</mesh>" << endl;
stream << "\t\t</geometry>" << endl;
stream << "\t</library_geometries>" << endl;
stream << "\t<scene>" << endl;
stream << "\t\t<instance_visual_scene url=\"#Scene\"/>" << endl;
stream << "\t</scene>" << endl;
}
void OutputEndHeader(ofstream& stream) {
stream << "</COLLADA>";
}
Im currently trying to output a 3D model to a dae file. The current issue is that Blender (and other model viewers) will not open the file. I am not getting any errors from blender. I followed examples of dae online and I think I have everything needed. All I have to output right now is faces and vertices. Previously, I was outputting this to an obj without issues.
I cant figure out if I am missing something.
Down below I have an example of the dae file that is being output by my code. For our sanity, I removed the 4000 vertices and faces from the output shown below.
<?xml version="1.0" encoding="UTF-8"?>
<COLLADA version="1.4.1">
<asset>
<contributor>
<author>Justin (JDOG) Barren</author>
<authoring_tool>RaxToDae File Ripper</authoring_tool>
</contributor>
<unit meter="1.000000"/>
<up_axis>Z_UP</up_axis>
</asset>
<library_geometries>
<geometry id="F1" name="allModel">
<mesh>
<source id="allModel-vertex-positions">
<float_array id="ID2-array" count="14442"> [ ...lots of numbers... ] </float_array>
<technique_common>
<accessor source="#ID2-array" count="4814" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="allModel-vertices">
<input semantic="POSITION" source="#allModel-vertex-positions">
</vertices>
<triangles count="4842">
<input semantic="VERTEX" offset="0" source="#allModel-vertices"/>
<p> [ ...lots of numbers... ] </p>
</triangles>
</mesh>
</geometry>
</library_geometries>
<scene>
<instance_visual_scene url="#Scene"/>
</scene>
</COLLADA>
This is my code to generate the file in c++.
void OutputHeader(ofstream& stream) {
stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
//stream << "<COLLADA xmlns=\"http://www.collada.org/2005/11/COLLADASchema\" version=\"1.4.1\">" << endl;
stream << "<COLLADA version=\"1.4.1\">" << endl;
stream << "\t<asset>" << endl;
stream << "\t\t<contributor>" << endl;
stream << "\t\t\t<author>Justin (JDOG) Barren</author>" << endl;
stream << "\t\t\t<authoring_tool>RaxToDae File Ripper</authoring_tool>" << endl;
stream << "\t\t</contributor>" << endl;
stream << "\t\t<unit meter=\"1.000000\"/>" << endl;
stream << "\t\t<up_axis>Z_UP</up_axis>" << endl;
stream << "\t</asset>" << endl;
}
void OutputVertsAndFaces(ofstream& stream, string modelName, int vertCount, int faceCount, vector <float> verts, vector <short> faces) {
stream << "\t<library_geometries>" << endl;
stream << "\t\t<geometry id=\"F1\" name=\"" << modelName << "\">" << endl;
stream << "\t\t\t<mesh>" << endl;
stream << "\t\t\t\t<source id=\"" << modelName << "-vertex-positions\">" << endl;
stream << "\t\t\t\t\t<float_array id=\"ID2-array\" count=\"" << vertCount << "\">" << endl; for (int i = 0; i < verts.size(); i++) stream << verts[i] << " "; stream << "</float_array>" << endl;
stream << "\t\t\t\t\t<technique_common>" << endl;
stream << "\t\t\t\t\t\t<accessor source=\"#ID2-array\" count=\"" << vertCount/3 << "\" stride=\"3\">" << endl;
stream << "\t\t\t\t\t\t\t<param name=\"X\" type=\"float\"/>" << endl;
stream << "\t\t\t\t\t\t\t<param name=\"Y\" type=\"float\"/>" << endl;
stream << "\t\t\t\t\t\t\t<param name=\"Z\" type=\"float\"/>" << endl;
stream << "\t\t\t\t\t\t</accessor>" << endl;
stream << "\t\t\t\t\t</technique_common>" << endl;
stream << "\t\t\t\t</source>" << endl;
stream << "\t\t\t\t<vertices id=\"" << modelName << "-vertices\">" << endl;
stream << "\t\t\t\t\t<input semantic=\"POSITION\" source=\"#" << modelName << "-vertex-positions\">" << endl;
stream << "\t\t\t\t</vertices>" << endl;
stream << "\t\t\t\t<triangles count=\"" << faceCount << "\">" << endl;
stream << "\t\t\t\t\t<input semantic=\"VERTEX\" offset=\"0\" source=\"#" << modelName << "-vertices\"/>" << endl;
stream << "\t\t\t\t\t<p>"; for (int i = 0; i < faces.size(); i++) stream << faces[i] << " "; stream << "</p>" << endl;
stream << "\t\t\t\t</triangles>" << endl;
stream << "\t\t\t</mesh>" << endl;
stream << "\t\t</geometry>" << endl;
stream << "\t</library_geometries>" << endl;
stream << "\t<scene>" << endl;
stream << "\t\t<instance_visual_scene url=\"#Scene\"/>" << endl;
stream << "\t</scene>" << endl;
}
void OutputEndHeader(ofstream& stream) {
stream << "</COLLADA>";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论