diff --git a/README.md b/README.md index efd3123..2f39878 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ The repository is separated into two parts. See more information in the [Develop - stl (text and binary) - ply (text and binary) - gltf (text and binary) +- 3dm (experimental) - off (text only) ## Features diff --git a/source/export/exporter.js b/source/export/exporter.js index 9479972..54eb751 100644 --- a/source/export/exporter.js +++ b/source/export/exporter.js @@ -11,6 +11,11 @@ OV.Exporter = class ]; } + AddExporter (exporter) + { + this.exporters.push (exporter); + } + Export (model, format, extension, callbacks) { let exporter = null; diff --git a/source/export/exportergltf.js b/source/export/exportergltf.js index d041926..4d679ac 100644 --- a/source/export/exportergltf.js +++ b/source/export/exportergltf.js @@ -196,9 +196,8 @@ OV.ExporterGltf = class extends OV.ExporterBase let writer = new OV.BinaryWriter (mainBufferSize, true); for (let meshIndex = 0; meshIndex < meshDataArr.length; meshIndex++) { let meshData = meshDataArr[meshIndex]; - let primitives = meshData.buffer.primitives; - for (let primitiveIndex = 0; primitiveIndex < primitives.length; primitiveIndex++) { - let primitive = primitives[primitiveIndex]; + for (let primitiveIndex = 0; primitiveIndex < meshData.buffer.PrimitiveCount (); primitiveIndex++) { + let primitive = meshData.buffer.GetPrimitive (primitiveIndex); let offset = writer.GetPosition (); for (let i = 0; i < primitive.indices.length; i++) { writer.WriteUnsignedInteger32 (primitive.indices[i]); diff --git a/source/external/rhino.exporter.js b/source/external/rhino.exporter.js new file mode 100644 index 0000000..1fb2c0a --- /dev/null +++ b/source/external/rhino.exporter.js @@ -0,0 +1,95 @@ +OV.Exporter3dm = class extends OV.ExporterBase +{ + constructor () + { + super (); + this.rhino = null; + } + + CanExport (format, extension) + { + return format === OV.FileFormat.Binary && extension === '3dm'; + } + + ExportContent (model, format, files, onFinish) + { + if (this.rhino === null) { + let obj = this; + rhino3dm ().then (function (rhino) { + obj.rhino = rhino; + obj.ExportRhinoContent (model, files, onFinish); + }); + } else { + this.ExportRhinoContent (model, files, onFinish); + } + } + + ExportRhinoContent (model, files, onFinish) + { + function ColorToRhinoColor (color) + { + return { + r : color.r, + g : color.g, + b : color.b, + a : 255 + }; + } + + let rhinoFile = new OV.ExportedFile ('model.3dm'); + files.push (rhinoFile); + + let rhinoDoc = new this.rhino.File3dm (); + for (let meshIndex = 0; meshIndex < model.MeshCount (); meshIndex++) { + let mesh = model.GetMesh (meshIndex); + let meshBuffer = OV.ConvertMeshToMeshBuffer (mesh); + for (let primitiveIndex = 0; primitiveIndex < meshBuffer.PrimitiveCount (); primitiveIndex++) { + let primitive = meshBuffer.GetPrimitive (primitiveIndex); + let threeJson = { + data : { + attributes : { + position : { + itemSize : 3, + type : 'Float32Array', + array : primitive.vertices + }, + normal : { + itemSize : 3, + type : 'Float32Array', + array : primitive.normals + } + }, + index : { + type : 'Uint16Array', + array : primitive.indices + } + } + }; + + let material = model.GetMaterial (primitive.material); + let rhinoMaterial = new this.rhino.Material (); + rhinoMaterial.name = material.name; + rhinoMaterial.ambientColor = ColorToRhinoColor (material.ambient); + rhinoMaterial.diffuseColor = ColorToRhinoColor (material.diffuse); + rhinoMaterial.specularColor = ColorToRhinoColor (material.specular); + rhinoMaterial.transparency = 1.0 - material.opacity; + + let rhinoMaterialIndex = rhinoDoc.materials ().count (); + rhinoDoc.materials ().add (rhinoMaterial); + + let rhinoMesh = new this.rhino.Mesh.createFromThreejsJSON (threeJson); + let rhinoAttributes = new this.rhino.ObjectAttributes (); + rhinoAttributes.materialSource = this.rhino.ObjectMaterialSource.MaterialFromObject; + rhinoAttributes.materialIndex = rhinoMaterialIndex; + rhinoDoc.objects ().add (rhinoMesh, rhinoAttributes); + } + } + + let writeOptions = new this.rhino.File3dmWriteOptions (); + writeOptions.version = 6; + let rhinoDocBuffer = rhinoDoc.toByteArray (writeOptions); + + rhinoFile.SetContent (rhinoDocBuffer); + onFinish (); + } +}; diff --git a/source/model/meshbuffer.js b/source/model/meshbuffer.js index 0965b3f..a2d0185 100644 --- a/source/model/meshbuffer.js +++ b/source/model/meshbuffer.js @@ -40,6 +40,16 @@ OV.MeshBuffer = class this.primitives = []; } + PrimitiveCount () + { + return this.primitives.length; + } + + GetPrimitive (index) + { + return this.primitives[index]; + } + GetByteLength (indexTypeSize, numberTypeSize) { let byteLength = 0; diff --git a/source/viewer/domviewer.js b/source/viewer/domviewer.js index 1f3f88d..1b16603 100644 --- a/source/viewer/domviewer.js +++ b/source/viewer/domviewer.js @@ -10,7 +10,6 @@ OV.Init3DViewerElements = function () let width = element.clientWidth; let height = element.clientHeight; - console.log (element.clientHeight); viewer.Resize (width, height); let loader = new OV.ThreeModelLoader (); diff --git a/tools/config.json b/tools/config.json index a011d31..470cb49 100644 --- a/tools/config.json +++ b/tools/config.json @@ -42,6 +42,7 @@ "source/export/exportergltf.js", "source/export/exporter.js", "source/external/rhino.importer.js", + "source/external/rhino.exporter.js", "source/external/three.converter.js", "source/external/three.model.loader.js", "source/parameters/parameterlist.js", diff --git a/tools/sandbox/embed_selfhost_fullscreen.html b/tools/sandbox/embed_selfhost_fullscreen.html index 166a0dc..cbd6f19 100644 --- a/tools/sandbox/embed_selfhost_fullscreen.html +++ b/tools/sandbox/embed_selfhost_fullscreen.html @@ -46,6 +46,7 @@ + diff --git a/tools/sandbox/embed_selfhost_multiple.html b/tools/sandbox/embed_selfhost_multiple.html index 21118e4..c4d18c7 100644 --- a/tools/sandbox/embed_selfhost_multiple.html +++ b/tools/sandbox/embed_selfhost_multiple.html @@ -48,6 +48,7 @@ + diff --git a/tools/sandbox/embed_selfhost_single.html b/tools/sandbox/embed_selfhost_single.html index df532d9..29276c2 100644 --- a/tools/sandbox/embed_selfhost_single.html +++ b/tools/sandbox/embed_selfhost_single.html @@ -46,6 +46,7 @@ + diff --git a/website/embed.html b/website/embed.html index 5653bff..473a291 100644 --- a/website/embed.html +++ b/website/embed.html @@ -55,6 +55,7 @@ + diff --git a/website/index.html b/website/index.html index 04911c9..12d81c2 100644 --- a/website/index.html +++ b/website/index.html @@ -55,6 +55,7 @@ + diff --git a/website/info/index.html b/website/info/index.html index a377ab0..fa22572 100644 --- a/website/info/index.html +++ b/website/info/index.html @@ -116,7 +116,7 @@