Add Rhino exporter.
This commit is contained in:
parent
1bc47cfa08
commit
0d329ea37b
@ -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
|
||||
|
||||
@ -11,6 +11,11 @@ OV.Exporter = class
|
||||
];
|
||||
}
|
||||
|
||||
AddExporter (exporter)
|
||||
{
|
||||
this.exporters.push (exporter);
|
||||
}
|
||||
|
||||
Export (model, format, extension, callbacks)
|
||||
{
|
||||
let exporter = null;
|
||||
|
||||
@ -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]);
|
||||
|
||||
95
source/external/rhino.exporter.js
vendored
Normal file
95
source/external/rhino.exporter.js
vendored
Normal file
@ -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 ();
|
||||
}
|
||||
};
|
||||
@ -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;
|
||||
|
||||
@ -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 ();
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -46,6 +46,7 @@
|
||||
<script type="text/javascript" src="../../source/export/exportergltf.js"></script>
|
||||
<script type="text/javascript" src="../../source/export/exporter.js"></script>
|
||||
<script type="text/javascript" src="../../source/external/rhino.importer.js"></script>
|
||||
<script type="text/javascript" src="../../source/external/rhino.exporter.js"></script>
|
||||
<script type="text/javascript" src="../../source/external/three.converter.js"></script>
|
||||
<script type="text/javascript" src="../../source/external/three.model.loader.js"></script>
|
||||
<script type="text/javascript" src="../../source/parameters/parameterlist.js"></script>
|
||||
|
||||
@ -48,6 +48,7 @@
|
||||
<script type="text/javascript" src="../../source/export/exportergltf.js"></script>
|
||||
<script type="text/javascript" src="../../source/export/exporter.js"></script>
|
||||
<script type="text/javascript" src="../../source/external/rhino.importer.js"></script>
|
||||
<script type="text/javascript" src="../../source/external/rhino.exporter.js"></script>
|
||||
<script type="text/javascript" src="../../source/external/three.converter.js"></script>
|
||||
<script type="text/javascript" src="../../source/external/three.model.loader.js"></script>
|
||||
<script type="text/javascript" src="../../source/parameters/parameterlist.js"></script>
|
||||
|
||||
@ -46,6 +46,7 @@
|
||||
<script type="text/javascript" src="../../source/export/exportergltf.js"></script>
|
||||
<script type="text/javascript" src="../../source/export/exporter.js"></script>
|
||||
<script type="text/javascript" src="../../source/external/rhino.importer.js"></script>
|
||||
<script type="text/javascript" src="../../source/external/rhino.exporter.js"></script>
|
||||
<script type="text/javascript" src="../../source/external/three.converter.js"></script>
|
||||
<script type="text/javascript" src="../../source/external/three.model.loader.js"></script>
|
||||
<script type="text/javascript" src="../../source/parameters/parameterlist.js"></script>
|
||||
|
||||
@ -55,6 +55,7 @@
|
||||
<script type="text/javascript" src="../source/export/exportergltf.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporter.js"></script>
|
||||
<script type="text/javascript" src="../source/external/rhino.importer.js"></script>
|
||||
<script type="text/javascript" src="../source/external/rhino.exporter.js"></script>
|
||||
<script type="text/javascript" src="../source/external/three.converter.js"></script>
|
||||
<script type="text/javascript" src="../source/external/three.model.loader.js"></script>
|
||||
<script type="text/javascript" src="../source/parameters/parameterlist.js"></script>
|
||||
|
||||
@ -55,6 +55,7 @@
|
||||
<script type="text/javascript" src="../source/export/exportergltf.js"></script>
|
||||
<script type="text/javascript" src="../source/export/exporter.js"></script>
|
||||
<script type="text/javascript" src="../source/external/rhino.importer.js"></script>
|
||||
<script type="text/javascript" src="../source/external/rhino.exporter.js"></script>
|
||||
<script type="text/javascript" src="../source/external/three.converter.js"></script>
|
||||
<script type="text/javascript" src="../source/external/three.model.loader.js"></script>
|
||||
<script type="text/javascript" src="../source/parameters/parameterlist.js"></script>
|
||||
|
||||
@ -116,7 +116,7 @@
|
||||
<td>3dm</td>
|
||||
<td>binary</td>
|
||||
<td class="center green">✓</td>
|
||||
<td class="center red">✗</td>
|
||||
<td class="center green">✓</td>
|
||||
<td>experimental</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
@ -44,6 +44,12 @@ OV.ExportDialog = class
|
||||
{ name : 'text', type: OV.ExportType.Model, format : OV.FileFormat.Text, extension : 'off' }
|
||||
]
|
||||
},
|
||||
{
|
||||
name : '3dm',
|
||||
formats : [
|
||||
{ name : 'binary', type: OV.ExportType.Model, format : OV.FileFormat.Binary, extension : '3dm' }
|
||||
]
|
||||
},
|
||||
{
|
||||
name : 'png',
|
||||
formats : [
|
||||
@ -157,6 +163,7 @@ OV.ExportDialog = class
|
||||
progressDialog.Show ('Exporting Model');
|
||||
OV.RunTaskAsync (function () {
|
||||
let exporter = new OV.Exporter ();
|
||||
exporter.AddExporter (new OV.Exporter3dm ());
|
||||
exporter.Export (model, selectedFormat.format, selectedFormat.extension, {
|
||||
onError : function () {
|
||||
progressDialog.Hide ();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user