diff --git a/sandbox/embed_edges.html b/sandbox/embed_edges.html
index ada715c..8de44c7 100644
--- a/sandbox/embed_edges.html
+++ b/sandbox/embed_edges.html
@@ -56,6 +56,7 @@
+
diff --git a/sandbox/embed_filehost.html b/sandbox/embed_filehost.html
index b93520f..e86b533 100644
--- a/sandbox/embed_filehost.html
+++ b/sandbox/embed_filehost.html
@@ -56,6 +56,7 @@
+
diff --git a/sandbox/embed_selfhost_code.html b/sandbox/embed_selfhost_code.html
index e78758d..b0a7a79 100644
--- a/sandbox/embed_selfhost_code.html
+++ b/sandbox/embed_selfhost_code.html
@@ -56,6 +56,7 @@
+
diff --git a/sandbox/embed_selfhost_errors.html b/sandbox/embed_selfhost_errors.html
index 77172b6..fae2cc1 100644
--- a/sandbox/embed_selfhost_errors.html
+++ b/sandbox/embed_selfhost_errors.html
@@ -56,6 +56,7 @@
+
diff --git a/sandbox/embed_selfhost_externallibs.html b/sandbox/embed_selfhost_externallibs.html
index ab0e8eb..8786cb4 100644
--- a/sandbox/embed_selfhost_externallibs.html
+++ b/sandbox/embed_selfhost_externallibs.html
@@ -56,6 +56,7 @@
+
diff --git a/sandbox/embed_selfhost_fullscreen.html b/sandbox/embed_selfhost_fullscreen.html
index 280b2ab..d582929 100644
--- a/sandbox/embed_selfhost_fullscreen.html
+++ b/sandbox/embed_selfhost_fullscreen.html
@@ -55,6 +55,7 @@
+
diff --git a/sandbox/embed_selfhost_manual.html b/sandbox/embed_selfhost_manual.html
index 3273581..ef23b9f 100644
--- a/sandbox/embed_selfhost_manual.html
+++ b/sandbox/embed_selfhost_manual.html
@@ -56,6 +56,7 @@
+
diff --git a/sandbox/embed_selfhost_multiple.html b/sandbox/embed_selfhost_multiple.html
index f3f1051..a80cbbc 100644
--- a/sandbox/embed_selfhost_multiple.html
+++ b/sandbox/embed_selfhost_multiple.html
@@ -56,6 +56,7 @@
+
diff --git a/sandbox/embed_selfhost_single.html b/sandbox/embed_selfhost_single.html
index d1023c5..2c24360 100644
--- a/sandbox/embed_selfhost_single.html
+++ b/sandbox/embed_selfhost_single.html
@@ -55,6 +55,7 @@
+
diff --git a/sandbox/embed_selfhost_single_scroll.html b/sandbox/embed_selfhost_single_scroll.html
index d78983b..64938f6 100644
--- a/sandbox/embed_selfhost_single_scroll.html
+++ b/sandbox/embed_selfhost_single_scroll.html
@@ -55,6 +55,7 @@
+
diff --git a/source/export/exporter3dm.js b/source/export/exporter3dm.js
index 16b57a6..fd62300 100644
--- a/source/export/exporter3dm.js
+++ b/source/export/exporter3dm.js
@@ -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) {
diff --git a/source/export/exporterbase.js b/source/export/exporterbase.js
index 0d4e761..40ed73b 100644
--- a/source/export/exporterbase.js
+++ b/source/export/exporterbase.js
@@ -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)
{
diff --git a/source/export/exportergltf.js b/source/export/exportergltf.js
index c6a0ba5..033fd14 100644
--- a/source/export/exportergltf.js
+++ b/source/export/exportergltf.js
@@ -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);
}
}
diff --git a/source/export/exportermodel.js b/source/export/exportermodel.js
new file mode 100644
index 0000000..3bab81c
--- /dev/null
+++ b/source/export/exportermodel.js
@@ -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);
+ });
+ });
+ }
+};
diff --git a/source/export/exporterobj.js b/source/export/exporterobj.js
index 95a74d2..286efe2 100644
--- a/source/export/exporterobj.js
+++ b/source/export/exporterobj.js
@@ -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]);
diff --git a/source/export/exporteroff.js b/source/export/exporteroff.js
index 59b9eeb..0cdbf24 100644
--- a/source/export/exporteroff.js
+++ b/source/export/exporteroff.js
@@ -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]);
},
diff --git a/source/export/exporterply.js b/source/export/exporterply.js
index 9b9a93b..7163424 100644
--- a/source/export/exporterply.js
+++ b/source/export/exporterply.js
@@ -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);
diff --git a/source/export/exporterstl.js b/source/export/exporterstl.js
index f9f884f..29f083c 100644
--- a/source/export/exporterstl.js
+++ b/source/export/exporterstl.js
@@ -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);
diff --git a/source/model/modelutils.js b/source/model/modelutils.js
index 688d3c5..c0e8055 100644
--- a/source/model/modelutils.js
+++ b/source/model/modelutils.js
@@ -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 ();
diff --git a/tools/config.json b/tools/config.json
index b999a57..218840a 100644
--- a/tools/config.json
+++ b/tools/config.json
@@ -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",
diff --git a/website/embed.html b/website/embed.html
index a37c07a..fa7a901 100644
--- a/website/embed.html
+++ b/website/embed.html
@@ -62,6 +62,7 @@
+
diff --git a/website/index.html b/website/index.html
index 00d0d4e..515dcb9 100644
--- a/website/index.html
+++ b/website/index.html
@@ -64,6 +64,7 @@
+