Use a separate model class for export.
This commit is contained in:
parent
233cc2c2d7
commit
fe8012e657
@ -56,6 +56,7 @@
|
||||
<script type="text/javascript" src="../source/import/importerifc.js"></script>
|
||||
<script type="text/javascript" src="../source/import/filelist.js"></script>
|
||||
<script type="text/javascript" src="../source/import/importer.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
|
||||
|
||||
@ -56,6 +56,7 @@
|
||||
<script type="text/javascript" src="../source/import/importerifc.js"></script>
|
||||
<script type="text/javascript" src="../source/import/filelist.js"></script>
|
||||
<script type="text/javascript" src="../source/import/importer.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
|
||||
|
||||
@ -56,6 +56,7 @@
|
||||
<script type="text/javascript" src="../source/import/importerifc.js"></script>
|
||||
<script type="text/javascript" src="../source/import/filelist.js"></script>
|
||||
<script type="text/javascript" src="../source/import/importer.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
|
||||
|
||||
@ -56,6 +56,7 @@
|
||||
<script type="text/javascript" src="../source/import/importerifc.js"></script>
|
||||
<script type="text/javascript" src="../source/import/filelist.js"></script>
|
||||
<script type="text/javascript" src="../source/import/importer.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
|
||||
|
||||
@ -56,6 +56,7 @@
|
||||
<script type="text/javascript" src="../source/import/importerifc.js"></script>
|
||||
<script type="text/javascript" src="../source/import/filelist.js"></script>
|
||||
<script type="text/javascript" src="../source/import/importer.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
|
||||
|
||||
@ -55,6 +55,7 @@
|
||||
<script type="text/javascript" src="../source/import/importerifc.js"></script>
|
||||
<script type="text/javascript" src="../source/import/filelist.js"></script>
|
||||
<script type="text/javascript" src="../source/import/importer.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
|
||||
|
||||
@ -56,6 +56,7 @@
|
||||
<script type="text/javascript" src="../source/import/importerifc.js"></script>
|
||||
<script type="text/javascript" src="../source/import/filelist.js"></script>
|
||||
<script type="text/javascript" src="../source/import/importer.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
|
||||
|
||||
@ -56,6 +56,7 @@
|
||||
<script type="text/javascript" src="../source/import/importerifc.js"></script>
|
||||
<script type="text/javascript" src="../source/import/filelist.js"></script>
|
||||
<script type="text/javascript" src="../source/import/importer.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
|
||||
|
||||
@ -55,6 +55,7 @@
|
||||
<script type="text/javascript" src="../source/import/importerifc.js"></script>
|
||||
<script type="text/javascript" src="../source/import/filelist.js"></script>
|
||||
<script type="text/javascript" src="../source/import/importer.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
|
||||
|
||||
@ -55,6 +55,7 @@
|
||||
<script type="text/javascript" src="../source/import/importerifc.js"></script>
|
||||
<script type="text/javascript" src="../source/import/filelist.js"></script>
|
||||
<script type="text/javascript" src="../source/import/importer.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
|
||||
|
||||
@ -11,23 +11,23 @@ OV.Exporter3dm = class extends OV.ExporterBase
|
||||
return format === OV.FileFormat.Binary && extension === '3dm';
|
||||
}
|
||||
|
||||
ExportContent (model, format, files, onFinish)
|
||||
ExportContent (exporterModel, format, files, onFinish)
|
||||
{
|
||||
if (this.rhino === null) {
|
||||
OV.LoadExternalLibrary ('loaders/rhino3dm.min.js').then (() => {
|
||||
rhino3dm ().then ((rhino) => {
|
||||
this.rhino = rhino;
|
||||
this.ExportRhinoContent (model, files, onFinish);
|
||||
this.ExportRhinoContent (exporterModel, files, onFinish);
|
||||
});
|
||||
}).catch (() => {
|
||||
onFinish ();
|
||||
});
|
||||
} else {
|
||||
this.ExportRhinoContent (model, files, onFinish);
|
||||
this.ExportRhinoContent (exporterModel, files, onFinish);
|
||||
}
|
||||
}
|
||||
|
||||
ExportRhinoContent (model, files, onFinish)
|
||||
ExportRhinoContent (exporterModel, files, onFinish)
|
||||
{
|
||||
function ColorToRhinoColor (color)
|
||||
{
|
||||
@ -43,7 +43,7 @@ OV.Exporter3dm = class extends OV.ExporterBase
|
||||
files.push (rhinoFile);
|
||||
|
||||
let rhinoDoc = new this.rhino.File3dm ();
|
||||
model.EnumerateTransformedMeshes ((mesh) => {
|
||||
exporterModel.EnumerateTransformedMeshes ((mesh) => {
|
||||
let meshBuffer = OV.ConvertMeshToMeshBuffer (mesh);
|
||||
for (let primitiveIndex = 0; primitiveIndex < meshBuffer.PrimitiveCount (); primitiveIndex++) {
|
||||
let primitive = meshBuffer.GetPrimitive (primitiveIndex);
|
||||
@ -68,7 +68,7 @@ OV.Exporter3dm = class extends OV.ExporterBase
|
||||
}
|
||||
};
|
||||
|
||||
let material = model.GetMaterial (primitive.material);
|
||||
let material = exporterModel.GetMaterial (primitive.material);
|
||||
let rhinoMaterial = new this.rhino.Material ();
|
||||
rhinoMaterial.name = this.GetExportedMaterialName (material.name);
|
||||
if (material.type === OV.MaterialType.Phong) {
|
||||
|
||||
@ -50,16 +50,17 @@ OV.ExporterBase = class
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Export (model, format, onFinish)
|
||||
{
|
||||
let files = [];
|
||||
this.ExportContent (model, format, files, () => {
|
||||
let exporterModel = new OV.ExporterModel (model);
|
||||
this.ExportContent (exporterModel, format, files, () => {
|
||||
onFinish (files);
|
||||
});
|
||||
}
|
||||
|
||||
ExportContent (model, format, files, onFinish)
|
||||
ExportContent (exporterModel, format, files, onFinish)
|
||||
{
|
||||
|
||||
}
|
||||
@ -68,11 +69,11 @@ OV.ExporterBase = class
|
||||
{
|
||||
return this.GetExportedName (originalName, 'Material');
|
||||
}
|
||||
|
||||
|
||||
GetExportedMeshName (originalName)
|
||||
{
|
||||
return this.GetExportedName (originalName, 'Mesh');
|
||||
}
|
||||
}
|
||||
|
||||
GetExportedName (originalName, defaultName)
|
||||
{
|
||||
|
||||
@ -20,24 +20,24 @@ OV.ExporterGltf = class extends OV.ExporterBase
|
||||
return (format === OV.FileFormat.Text && extension === 'gltf') || (format === OV.FileFormat.Binary && extension === 'glb');
|
||||
}
|
||||
|
||||
ExportContent (model, format, files, onFinish)
|
||||
ExportContent (exporterModel, format, files, onFinish)
|
||||
{
|
||||
if (format === OV.FileFormat.Text) {
|
||||
this.ExportAsciiContent (model, files);
|
||||
this.ExportAsciiContent (exporterModel, files);
|
||||
} else if (format === OV.FileFormat.Binary) {
|
||||
this.ExportBinaryContent (model, files);
|
||||
this.ExportBinaryContent (exporterModel, files);
|
||||
}
|
||||
onFinish ();
|
||||
}
|
||||
|
||||
ExportAsciiContent (model, files)
|
||||
ExportAsciiContent (exporterModel, files)
|
||||
{
|
||||
let gltfFile = new OV.ExportedFile ('model.gltf');
|
||||
let binFile = new OV.ExportedFile ('model.bin');
|
||||
files.push (gltfFile);
|
||||
files.push (binFile);
|
||||
|
||||
let meshDataArr = this.GetMeshData (model);
|
||||
let meshDataArr = this.GetMeshData (exporterModel);
|
||||
let mainBuffer = this.GetMainBuffer (meshDataArr);
|
||||
let mainJson = this.GetMainJson (meshDataArr);
|
||||
mainJson.buffers.push ({
|
||||
@ -46,7 +46,7 @@ OV.ExporterGltf = class extends OV.ExporterBase
|
||||
});
|
||||
|
||||
let fileNameToIndex = new Map ();
|
||||
this.ExportMaterials (model, mainJson, (texture) => {
|
||||
this.ExportMaterials (exporterModel, mainJson, (texture) => {
|
||||
let fileName = OV.GetFileName (texture.name);
|
||||
if (fileNameToIndex.has (fileName)) {
|
||||
return fileNameToIndex.get (fileName);
|
||||
@ -74,7 +74,7 @@ OV.ExporterGltf = class extends OV.ExporterBase
|
||||
binFile.SetBufferContent (mainBuffer);
|
||||
}
|
||||
|
||||
ExportBinaryContent (model, files)
|
||||
ExportBinaryContent (exporterModel, files)
|
||||
{
|
||||
function AlignToBoundary (size)
|
||||
{
|
||||
@ -95,7 +95,7 @@ OV.ExporterGltf = class extends OV.ExporterBase
|
||||
let glbFile = new OV.ExportedFile ('model.glb');
|
||||
files.push (glbFile);
|
||||
|
||||
let meshDataArr = this.GetMeshData (model);
|
||||
let meshDataArr = this.GetMeshData (exporterModel);
|
||||
let mainBuffer = this.GetMainBuffer (meshDataArr);
|
||||
let mainJson = this.GetMainJson (meshDataArr);
|
||||
|
||||
@ -103,7 +103,7 @@ OV.ExporterGltf = class extends OV.ExporterBase
|
||||
let textureOffset = mainBuffer.byteLength;
|
||||
|
||||
let fileNameToIndex = new Map ();
|
||||
this.ExportMaterials (model, mainJson, (texture) => {
|
||||
this.ExportMaterials (exporterModel, mainJson, (texture) => {
|
||||
let fileName = OV.GetFileName (texture.name);
|
||||
let extension = OV.GetFileExtension (texture.name);
|
||||
if (fileNameToIndex.has (fileName)) {
|
||||
@ -172,11 +172,11 @@ OV.ExporterGltf = class extends OV.ExporterBase
|
||||
glbFile.SetBufferContent (glbWriter.GetBuffer ());
|
||||
}
|
||||
|
||||
GetMeshData (model)
|
||||
GetMeshData (exporterModel)
|
||||
{
|
||||
let meshDataArr = [];
|
||||
|
||||
model.EnumerateTransformedMeshes ((mesh) => {
|
||||
exporterModel.EnumerateTransformedMeshes ((mesh) => {
|
||||
let buffer = OV.ConvertMeshToMeshBuffer (mesh);
|
||||
meshDataArr.push ({
|
||||
name : mesh.GetName (),
|
||||
@ -343,7 +343,7 @@ OV.ExporterGltf = class extends OV.ExporterBase
|
||||
return mainJson;
|
||||
}
|
||||
|
||||
ExportMaterials (model, mainJson, addTexture)
|
||||
ExportMaterials (exporterModel, mainJson, addTexture)
|
||||
{
|
||||
function ExportMaterial (obj, mainJson, material, addTexture)
|
||||
{
|
||||
@ -447,8 +447,8 @@ OV.ExporterGltf = class extends OV.ExporterBase
|
||||
mainJson.materials.push (jsonMaterial);
|
||||
}
|
||||
|
||||
for (let materialIndex = 0; materialIndex < model.MaterialCount (); materialIndex++) {
|
||||
let material = model.GetMaterial (materialIndex);
|
||||
for (let materialIndex = 0; materialIndex < exporterModel.MaterialCount (); materialIndex++) {
|
||||
let material = exporterModel.GetMaterial (materialIndex);
|
||||
ExportMaterial (this, mainJson, material, addTexture);
|
||||
}
|
||||
}
|
||||
|
||||
66
source/export/exportermodel.js
Normal file
66
source/export/exportermodel.js
Normal file
@ -0,0 +1,66 @@
|
||||
OV.ExporterModel = class
|
||||
{
|
||||
constructor (model)
|
||||
{
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
MaterialCount ()
|
||||
{
|
||||
return this.model.MaterialCount ();
|
||||
}
|
||||
|
||||
VertexCount ()
|
||||
{
|
||||
return this.model.VertexCount ();
|
||||
}
|
||||
|
||||
TriangleCount ()
|
||||
{
|
||||
return this.model.TriangleCount ();
|
||||
}
|
||||
|
||||
GetMaterial (index)
|
||||
{
|
||||
return this.model.GetMaterial (index);
|
||||
}
|
||||
|
||||
EnumerateMeshInstances (onMeshInstance)
|
||||
{
|
||||
this.model.EnumerateMeshInstances (onMeshInstance);
|
||||
}
|
||||
|
||||
EnumerateTransformedMeshes (onMesh)
|
||||
{
|
||||
this.EnumerateMeshInstances ((meshInstance) => {
|
||||
const transformed = meshInstance.GetTransformedMesh ();
|
||||
onMesh (transformed);
|
||||
});
|
||||
}
|
||||
|
||||
EnumerateVerticesAndTriangles (callbacks)
|
||||
{
|
||||
this.EnumerateMeshInstances ((meshInstance) => {
|
||||
meshInstance.EnumerateVertices ((vertex) => {
|
||||
callbacks.onVertex (vertex.x, vertex.y, vertex.z);
|
||||
});
|
||||
});
|
||||
let vertexOffset = 0;
|
||||
this.model.EnumerateMeshInstances ((meshInstance) => {
|
||||
meshInstance.EnumerateTriangleVertexIndices ((v0, v1, v2) => {
|
||||
callbacks.onTriangle (v0 + vertexOffset, v1 + vertexOffset, v2 + vertexOffset);
|
||||
});
|
||||
vertexOffset += meshInstance.VertexCount ();
|
||||
});
|
||||
}
|
||||
|
||||
EnumerateTrianglesWithNormals (onTriangle)
|
||||
{
|
||||
this.EnumerateMeshInstances ((meshInstance) => {
|
||||
meshInstance.EnumerateTriangleVertices ((v0, v1, v2) => {
|
||||
let normal = OV.CalculateTriangleNormal (v0, v1, v2);
|
||||
onTriangle (v0, v1, v2, normal);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -10,7 +10,7 @@ OV.ExporterObj = class extends OV.ExporterBase
|
||||
return format === OV.FileFormat.Text && extension === 'obj';
|
||||
}
|
||||
|
||||
ExportContent (model, format, files, onFinish)
|
||||
ExportContent (exporterModel, format, files, onFinish)
|
||||
{
|
||||
function WriteTexture (mtlWriter, keyword, texture, files)
|
||||
{
|
||||
@ -38,8 +38,8 @@ OV.ExporterObj = class extends OV.ExporterBase
|
||||
|
||||
let mtlWriter = new OV.TextWriter ();
|
||||
mtlWriter.WriteLine (this.GetHeaderText ());
|
||||
for (let materialIndex = 0; materialIndex < model.MaterialCount (); materialIndex++) {
|
||||
let material = model.GetMaterial (materialIndex);
|
||||
for (let materialIndex = 0; materialIndex < exporterModel.MaterialCount (); materialIndex++) {
|
||||
let material = exporterModel.GetMaterial (materialIndex);
|
||||
mtlWriter.WriteArrayLine (['newmtl', this.GetExportedMaterialName (material.name)]);
|
||||
mtlWriter.WriteArrayLine (['Kd', material.color.r / 255.0, material.color.g / 255.0, material.color.b / 255.0]);
|
||||
mtlWriter.WriteArrayLine (['d', material.opacity]);
|
||||
@ -63,7 +63,7 @@ OV.ExporterObj = class extends OV.ExporterBase
|
||||
let normalOffset = 0;
|
||||
let uvOffset = 0;
|
||||
let usedMaterialName = null;
|
||||
model.EnumerateTransformedMeshes ((mesh) => {
|
||||
exporterModel.EnumerateTransformedMeshes ((mesh) => {
|
||||
objWriter.WriteArrayLine (['g', this.GetExportedMeshName (mesh.GetName ())]);
|
||||
for (let vertexIndex = 0; vertexIndex < mesh.VertexCount (); vertexIndex++) {
|
||||
let vertex = mesh.GetVertex (vertexIndex);
|
||||
@ -86,7 +86,7 @@ OV.ExporterObj = class extends OV.ExporterBase
|
||||
let n1 = triangle.n1 + normalOffset + 1;
|
||||
let n2 = triangle.n2 + normalOffset + 1;
|
||||
if (triangle.mat !== null) {
|
||||
let material = model.GetMaterial (triangle.mat);
|
||||
let material = exporterModel.GetMaterial (triangle.mat);
|
||||
let materialName = this.GetExportedMaterialName (material.name);
|
||||
if (materialName !== usedMaterialName) {
|
||||
objWriter.WriteArrayLine (['usemtl', materialName]);
|
||||
|
||||
@ -10,16 +10,16 @@ OV.ExporterOff = class extends OV.ExporterBase
|
||||
return format === OV.FileFormat.Text && extension === 'off';
|
||||
}
|
||||
|
||||
ExportContent (model, format, files, onFinish)
|
||||
ExportContent (exporterModel, format, files, onFinish)
|
||||
{
|
||||
let offFile = new OV.ExportedFile ('model.off');
|
||||
files.push (offFile);
|
||||
|
||||
let offWriter = new OV.TextWriter ();
|
||||
offWriter.WriteLine ('OFF');
|
||||
offWriter.WriteArrayLine ([model.VertexCount (), model.TriangleCount (), 0]);
|
||||
offWriter.WriteArrayLine ([exporterModel.VertexCount (), exporterModel.TriangleCount (), 0]);
|
||||
|
||||
OV.EnumerateModelVerticesAndTriangles (model, {
|
||||
exporterModel.EnumerateVerticesAndTriangles ({
|
||||
onVertex : function (x, y, z) {
|
||||
offWriter.WriteArrayLine ([x, y, z]);
|
||||
},
|
||||
|
||||
@ -10,29 +10,29 @@ OV.ExporterPly = class extends OV.ExporterBase
|
||||
return (format === OV.FileFormat.Text || format === OV.FileFormat.Binary) && extension === 'ply';
|
||||
}
|
||||
|
||||
ExportContent (model, format, files, onFinish)
|
||||
ExportContent (exporterModel, format, files, onFinish)
|
||||
{
|
||||
if (format === OV.FileFormat.Text) {
|
||||
this.ExportText (model, files);
|
||||
this.ExportText (exporterModel, files);
|
||||
} else {
|
||||
this.ExportBinary (model, files);
|
||||
this.ExportBinary (exporterModel, files);
|
||||
}
|
||||
onFinish ();
|
||||
}
|
||||
|
||||
ExportText (model, files)
|
||||
ExportText (exporterModel, files)
|
||||
{
|
||||
let plyFile = new OV.ExportedFile ('model.ply');
|
||||
files.push (plyFile);
|
||||
|
||||
let plyWriter = new OV.TextWriter ();
|
||||
|
||||
let vertexCount = model.VertexCount ();
|
||||
let triangleCount = model.TriangleCount ();
|
||||
let vertexCount = exporterModel.VertexCount ();
|
||||
let triangleCount = exporterModel.TriangleCount ();
|
||||
let headerText = this.GetHeaderText ('ascii', vertexCount, triangleCount);
|
||||
plyWriter.Write (headerText);
|
||||
|
||||
OV.EnumerateModelVerticesAndTriangles (model, {
|
||||
exporterModel.EnumerateVerticesAndTriangles ({
|
||||
onVertex : function (x, y, z) {
|
||||
plyWriter.WriteArrayLine ([x, y, z]);
|
||||
},
|
||||
@ -44,13 +44,13 @@ OV.ExporterPly = class extends OV.ExporterBase
|
||||
plyFile.SetTextContent (plyWriter.GetText ());
|
||||
}
|
||||
|
||||
ExportBinary (model, files)
|
||||
ExportBinary (exporterModel, files)
|
||||
{
|
||||
let plyFile = new OV.ExportedFile ('model.ply');
|
||||
files.push (plyFile);
|
||||
|
||||
let vertexCount = model.VertexCount ();
|
||||
let triangleCount = model.TriangleCount ();
|
||||
let vertexCount = exporterModel.VertexCount ();
|
||||
let triangleCount = exporterModel.TriangleCount ();
|
||||
let headerText = this.GetHeaderText ('binary_little_endian', vertexCount, triangleCount);
|
||||
|
||||
let fullByteLength = headerText.length + vertexCount * 3 * 4 + triangleCount * (1 + 3 * 4);
|
||||
@ -60,7 +60,7 @@ OV.ExporterPly = class extends OV.ExporterBase
|
||||
plyWriter.WriteUnsignedCharacter8 (headerText.charCodeAt (i));
|
||||
}
|
||||
|
||||
OV.EnumerateModelVerticesAndTriangles (model, {
|
||||
exporterModel.EnumerateVerticesAndTriangles ({
|
||||
onVertex : function (x, y, z) {
|
||||
plyWriter.WriteFloat32 (x);
|
||||
plyWriter.WriteFloat32 (y);
|
||||
|
||||
@ -10,24 +10,24 @@ OV.ExporterStl = class extends OV.ExporterBase
|
||||
return (format === OV.FileFormat.Text || format === OV.FileFormat.Binary) && extension === 'stl';
|
||||
}
|
||||
|
||||
ExportContent (model, format, files, onFinish)
|
||||
ExportContent (exporterModel, format, files, onFinish)
|
||||
{
|
||||
if (format === OV.FileFormat.Text) {
|
||||
this.ExportText (model, files);
|
||||
this.ExportText (exporterModel, files);
|
||||
} else {
|
||||
this.ExportBinary (model, files);
|
||||
this.ExportBinary (exporterModel, files);
|
||||
}
|
||||
onFinish ();
|
||||
}
|
||||
|
||||
ExportText (model, files)
|
||||
ExportText (exporterModel, files)
|
||||
{
|
||||
let stlFile = new OV.ExportedFile ('model.stl');
|
||||
files.push (stlFile);
|
||||
|
||||
let stlWriter = new OV.TextWriter ();
|
||||
stlWriter.WriteLine ('solid Model');
|
||||
OV.EnumerateTrianglesWithNormals (model, (v0, v1, v2, normal) => {
|
||||
exporterModel.EnumerateTrianglesWithNormals ((v0, v1, v2, normal) => {
|
||||
stlWriter.WriteArrayLine (['facet', 'normal', normal.x, normal.y, normal.z]);
|
||||
stlWriter.Indent (1);
|
||||
stlWriter.WriteLine ('outer loop');
|
||||
@ -45,12 +45,12 @@ OV.ExporterStl = class extends OV.ExporterBase
|
||||
stlFile.SetTextContent (stlWriter.GetText ());
|
||||
}
|
||||
|
||||
ExportBinary (model, files)
|
||||
ExportBinary (exporterModel, files)
|
||||
{
|
||||
let stlFile = new OV.ExportedFile ('model.stl');
|
||||
files.push (stlFile);
|
||||
|
||||
let triangleCount = model.TriangleCount ();
|
||||
let triangleCount = exporterModel.TriangleCount ();
|
||||
let headerSize = 80;
|
||||
let fullByteLength = headerSize + 4 + triangleCount * 50;
|
||||
let stlWriter = new OV.BinaryWriter (fullByteLength, true);
|
||||
@ -60,7 +60,7 @@ OV.ExporterStl = class extends OV.ExporterBase
|
||||
}
|
||||
|
||||
stlWriter.WriteUnsignedInteger32 (triangleCount);
|
||||
OV.EnumerateTrianglesWithNormals (model, (v0, v1, v2, normal) => {
|
||||
exporterModel.EnumerateTrianglesWithNormals ((v0, v1, v2, normal) => {
|
||||
stlWriter.WriteFloat32 (normal.x);
|
||||
stlWriter.WriteFloat32 (normal.y);
|
||||
stlWriter.WriteFloat32 (normal.z);
|
||||
|
||||
@ -85,30 +85,6 @@ OV.CloneMesh = function (mesh)
|
||||
return cloned;
|
||||
};
|
||||
|
||||
OV.EnumerateModelVerticesAndTriangles = function (model, callbacks)
|
||||
{
|
||||
model.EnumerateMeshInstances ((meshInstance) => {
|
||||
meshInstance.EnumerateVertices ((vertex) => {
|
||||
callbacks.onVertex (vertex.x, vertex.y, vertex.z);
|
||||
});
|
||||
});
|
||||
let vertexOffset = 0;
|
||||
model.EnumerateMeshInstances ((meshInstance) => {
|
||||
meshInstance.EnumerateTriangleVertexIndices ((v0, v1, v2) => {
|
||||
callbacks.onTriangle (v0 + vertexOffset, v1 + vertexOffset, v2 + vertexOffset);
|
||||
});
|
||||
vertexOffset += meshInstance.VertexCount ();
|
||||
});
|
||||
};
|
||||
|
||||
OV.EnumerateTrianglesWithNormals = function (object3D, onTriangle)
|
||||
{
|
||||
object3D.EnumerateTriangleVertices ((v0, v1, v2) => {
|
||||
let normal = OV.CalculateTriangleNormal (v0, v1, v2);
|
||||
onTriangle (v0, v1, v2, normal);
|
||||
});
|
||||
};
|
||||
|
||||
OV.GetBoundingBox = function (object3D)
|
||||
{
|
||||
let calculator = new OV.BoundingBoxCalculator3D ();
|
||||
|
||||
@ -46,6 +46,7 @@
|
||||
"source/import/importerifc.js",
|
||||
"source/import/filelist.js",
|
||||
"source/import/importer.js",
|
||||
"source/export/exportermodel.js",
|
||||
"source/export/exporterbase.js",
|
||||
"source/export/exporterobj.js",
|
||||
"source/export/exporterstl.js",
|
||||
|
||||
@ -62,6 +62,7 @@
|
||||
<script type="text/javascript" src="../source/import/importerifc.js"></script>
|
||||
<script type="text/javascript" src="../source/import/filelist.js"></script>
|
||||
<script type="text/javascript" src="../source/import/importer.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
|
||||
|
||||
@ -64,6 +64,7 @@
|
||||
<script type="text/javascript" src="../source/import/importerifc.js"></script>
|
||||
<script type="text/javascript" src="../source/import/filelist.js"></script>
|
||||
<script type="text/javascript" src="../source/import/importer.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user