Remove o3dv importer.
This commit is contained in:
parent
3c69b36a0d
commit
feb4b81deb
@ -6,7 +6,6 @@ import { Importer3dm } from './importer3dm.js';
|
|||||||
import { Importer3ds } from './importer3ds.js';
|
import { Importer3ds } from './importer3ds.js';
|
||||||
import { ImporterGltf } from './importergltf.js';
|
import { ImporterGltf } from './importergltf.js';
|
||||||
import { ImporterIfc } from './importerifc.js';
|
import { ImporterIfc } from './importerifc.js';
|
||||||
import { ImporterO3dv } from './importero3dv.js';
|
|
||||||
import { ImporterObj } from './importerobj.js';
|
import { ImporterObj } from './importerobj.js';
|
||||||
import { ImporterOff } from './importeroff.js';
|
import { ImporterOff } from './importeroff.js';
|
||||||
import { ImporterPly } from './importerply.js';
|
import { ImporterPly } from './importerply.js';
|
||||||
@ -87,7 +86,6 @@ export class Importer
|
|||||||
new ImporterPly (),
|
new ImporterPly (),
|
||||||
new Importer3ds (),
|
new Importer3ds (),
|
||||||
new ImporterGltf (),
|
new ImporterGltf (),
|
||||||
new ImporterO3dv (),
|
|
||||||
new ImporterBim (),
|
new ImporterBim (),
|
||||||
new Importer3dm (),
|
new Importer3dm (),
|
||||||
new ImporterIfc (),
|
new ImporterIfc (),
|
||||||
|
|||||||
@ -1,195 +0,0 @@
|
|||||||
import { ValueOrDefault } from '../core/core.js';
|
|
||||||
import { ArrayToCoord3D, Coord3D } from '../geometry/coord3d.js';
|
|
||||||
import { Direction } from '../geometry/geometry.js';
|
|
||||||
import { Matrix } from '../geometry/matrix.js';
|
|
||||||
import { ArrayToQuaternion, Quaternion } from '../geometry/quaternion.js';
|
|
||||||
import { Transformation } from '../geometry/transformation.js';
|
|
||||||
import { ArrayBufferToUtf8String } from '../io/bufferutils.js';
|
|
||||||
import { ArrayToRGBColor } from '../model/color.js';
|
|
||||||
import { GenerateCone, GenerateCuboid, GenerateCylinder, GeneratePlatonicSolid, GenerateSphere, GeneratorParams } from '../model/generator.js';
|
|
||||||
import { PhysicalMaterial } from '../model/material.js';
|
|
||||||
import { Node, NodeType } from '../model/node.js';
|
|
||||||
import { Property, PropertyGroup, PropertyType } from '../model/property.js';
|
|
||||||
import { ImporterBase } from './importerbase.js';
|
|
||||||
|
|
||||||
export class ImporterO3dv extends ImporterBase
|
|
||||||
{
|
|
||||||
constructor ()
|
|
||||||
{
|
|
||||||
super ();
|
|
||||||
}
|
|
||||||
|
|
||||||
CanImportExtension (extension)
|
|
||||||
{
|
|
||||||
return extension === 'o3dv';
|
|
||||||
}
|
|
||||||
|
|
||||||
GetUpDirection ()
|
|
||||||
{
|
|
||||||
return Direction.Z;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClearContent ()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ResetContent ()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ImportContent (fileContent, onFinish)
|
|
||||||
{
|
|
||||||
let textContent = ArrayBufferToUtf8String (fileContent);
|
|
||||||
let content = JSON.parse (textContent);
|
|
||||||
if (content.root === undefined) {
|
|
||||||
onFinish ();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (content.materials !== undefined) {
|
|
||||||
for (let i = 0; i < content.materials.length; i++) {
|
|
||||||
const materialContent = content.materials[i];
|
|
||||||
this.ImportMaterial (materialContent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (content.meshes !== undefined) {
|
|
||||||
for (let i = 0; i < content.meshes.length; i++) {
|
|
||||||
const meshContent = content.meshes[i];
|
|
||||||
this.ImportMesh (meshContent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let rootNode = content.nodes[content.root];
|
|
||||||
this.ImportNode (content, rootNode, this.model.GetRootNode ());
|
|
||||||
this.ImportProperties (this.model, content);
|
|
||||||
|
|
||||||
onFinish ();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImportMaterial (materialContent)
|
|
||||||
{
|
|
||||||
let material = new PhysicalMaterial ();
|
|
||||||
material.color.Set (255, 255, 255);
|
|
||||||
if (materialContent.name !== undefined) {
|
|
||||||
material.name = materialContent.name;
|
|
||||||
}
|
|
||||||
if (materialContent.color !== undefined) {
|
|
||||||
material.color = ArrayToRGBColor (materialContent.color);
|
|
||||||
}
|
|
||||||
material.metalness = ValueOrDefault (materialContent.metalness, 0.0);
|
|
||||||
material.roughness = ValueOrDefault (materialContent.roughness, 1.0);
|
|
||||||
this.model.AddMaterial (material);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImportMesh (meshContent)
|
|
||||||
{
|
|
||||||
let genParams = new GeneratorParams ();
|
|
||||||
if (meshContent.name !== undefined) {
|
|
||||||
genParams.SetName (meshContent.name);
|
|
||||||
}
|
|
||||||
if (meshContent.material !== undefined) {
|
|
||||||
genParams.SetMaterial (meshContent.material);
|
|
||||||
}
|
|
||||||
|
|
||||||
let parameters = meshContent.parameters;
|
|
||||||
if (parameters === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mesh = null;
|
|
||||||
if (meshContent.type === 'cuboid') {
|
|
||||||
if (parameters.size_x === undefined || parameters.size_y === undefined || parameters.size_z === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mesh = GenerateCuboid (genParams, parameters.size_x, parameters.size_y, parameters.size_z);
|
|
||||||
} else if (meshContent.type === 'cylinder') {
|
|
||||||
if (parameters.radius === undefined || parameters.height === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let segments = ValueOrDefault (parameters.segments, 25);
|
|
||||||
let smooth = ValueOrDefault (parameters.smooth, true);
|
|
||||||
mesh = GenerateCylinder (genParams, parameters.radius, parameters.height, segments, smooth);
|
|
||||||
} else if (meshContent.type === 'cone') {
|
|
||||||
if (parameters.top_radius === undefined || parameters.bottom_radius === undefined || parameters.height === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let segments = ValueOrDefault (parameters.segments, 25);
|
|
||||||
let smooth = ValueOrDefault (parameters.smooth, true);
|
|
||||||
mesh = GenerateCone (genParams, parameters.top_radius, parameters.bottom_radius, parameters.height, segments, smooth);
|
|
||||||
} else if (meshContent.type === 'sphere') {
|
|
||||||
if (parameters.radius === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let segments = ValueOrDefault (parameters.segments, 20);
|
|
||||||
let smooth = ValueOrDefault (parameters.smooth, true);
|
|
||||||
mesh = GenerateSphere (genParams, parameters.radius, segments, smooth);
|
|
||||||
} else if (meshContent.type === 'platonic') {
|
|
||||||
if (parameters.solid_type === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let radius = ValueOrDefault (parameters.radius, 1.0);
|
|
||||||
mesh = GeneratePlatonicSolid (genParams, parameters.solid_type, radius);
|
|
||||||
}
|
|
||||||
if (mesh !== null) {
|
|
||||||
this.ImportProperties (mesh, meshContent);
|
|
||||||
this.model.AddMesh (mesh);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ImportNode (content, nodeContent, node)
|
|
||||||
{
|
|
||||||
if (nodeContent.name !== undefined) {
|
|
||||||
node.SetName (nodeContent.name);
|
|
||||||
}
|
|
||||||
if (nodeContent.transformation !== undefined) {
|
|
||||||
const nodeTransformation = this.GetTransformation (nodeContent.transformation);
|
|
||||||
node.SetTransformation (nodeTransformation);
|
|
||||||
}
|
|
||||||
if (nodeContent.children !== undefined) {
|
|
||||||
for (const childIndex of nodeContent.children) {
|
|
||||||
let childContent = content.nodes[childIndex];
|
|
||||||
let childNode = new Node ();
|
|
||||||
node.AddChildNode (childNode);
|
|
||||||
this.ImportNode (content, childContent, childNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (nodeContent.mesh !== undefined) {
|
|
||||||
if (nodeContent.children === undefined || nodeContent.children.length === 0) {
|
|
||||||
node.SetType (NodeType.MeshNode);
|
|
||||||
}
|
|
||||||
node.AddMeshIndex (nodeContent.mesh);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ImportProperties (element, nodeContent)
|
|
||||||
{
|
|
||||||
if (nodeContent.properties !== undefined) {
|
|
||||||
const propertyGroup = new PropertyGroup ('Properties');
|
|
||||||
element.AddPropertyGroup (propertyGroup);
|
|
||||||
for (const nodeProperty of nodeContent.properties) {
|
|
||||||
const property = new Property (PropertyType.Text, nodeProperty.name, nodeProperty.value);
|
|
||||||
propertyGroup.AddProperty (property);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GetTransformation (contentTransformation)
|
|
||||||
{
|
|
||||||
let translation = new Coord3D (0.0, 0.0, 0.0);
|
|
||||||
let rotation = new Quaternion (0.0, 0.0, 0.0, 1.0);
|
|
||||||
let scale = new Coord3D (1.0, 1.0, 1.0);
|
|
||||||
if (contentTransformation.translation !== undefined) {
|
|
||||||
translation = ArrayToCoord3D (contentTransformation.translation);
|
|
||||||
}
|
|
||||||
if (contentTransformation.rotation !== undefined) {
|
|
||||||
rotation = ArrayToQuaternion (contentTransformation.rotation);
|
|
||||||
}
|
|
||||||
if (contentTransformation.scale !== undefined) {
|
|
||||||
scale = ArrayToCoord3D (contentTransformation.scale);
|
|
||||||
}
|
|
||||||
const matrix = new Matrix ().ComposeTRS (translation, rotation, scale);
|
|
||||||
return new Transformation (matrix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -30,7 +30,6 @@ import { ImporterFcstd } from './import/importerfcstd.js';
|
|||||||
import { InputFile, ImporterFile, ImporterFileList, InputFilesFromUrls, InputFilesFromFileObjects } from './import/importerfiles.js';
|
import { InputFile, ImporterFile, ImporterFileList, InputFilesFromUrls, InputFilesFromFileObjects } from './import/importerfiles.js';
|
||||||
import { ImporterGltf } from './import/importergltf.js';
|
import { ImporterGltf } from './import/importergltf.js';
|
||||||
import { ImporterIfc } from './import/importerifc.js';
|
import { ImporterIfc } from './import/importerifc.js';
|
||||||
import { ImporterO3dv } from './import/importero3dv.js';
|
|
||||||
import { ImporterObj } from './import/importerobj.js';
|
import { ImporterObj } from './import/importerobj.js';
|
||||||
import { ImporterOcct } from './import/importerocct.js';
|
import { ImporterOcct } from './import/importerocct.js';
|
||||||
import { ImporterOff } from './import/importeroff.js';
|
import { ImporterOff } from './import/importeroff.js';
|
||||||
@ -161,7 +160,6 @@ export {
|
|||||||
InputFilesFromFileObjects,
|
InputFilesFromFileObjects,
|
||||||
ImporterGltf,
|
ImporterGltf,
|
||||||
ImporterIfc,
|
ImporterIfc,
|
||||||
ImporterO3dv,
|
|
||||||
ImporterObj,
|
ImporterObj,
|
||||||
ImporterOcct,
|
ImporterOcct,
|
||||||
ImporterOff,
|
ImporterOff,
|
||||||
|
|||||||
@ -18,7 +18,6 @@ import generator_test from './tests/generator_test.js';
|
|||||||
import importerutils_test from './tests/importerutils_test.js';
|
import importerutils_test from './tests/importerutils_test.js';
|
||||||
import importer3ds_test from './tests/importer3ds_test.js';
|
import importer3ds_test from './tests/importer3ds_test.js';
|
||||||
import importergltf_test from './tests/importergltf_test.js';
|
import importergltf_test from './tests/importergltf_test.js';
|
||||||
import importero3dv_test from './tests/importero3dv_test.js';
|
|
||||||
import importerobj_test from './tests/importerobj_test.js';
|
import importerobj_test from './tests/importerobj_test.js';
|
||||||
import importeroff_test from './tests/importeroff_test.js';
|
import importeroff_test from './tests/importeroff_test.js';
|
||||||
import importerply_test from './tests/importerply_test.js';
|
import importerply_test from './tests/importerply_test.js';
|
||||||
@ -50,7 +49,6 @@ generator_test ();
|
|||||||
importerutils_test ();
|
importerutils_test ();
|
||||||
importer3ds_test ();
|
importer3ds_test ();
|
||||||
importergltf_test ();
|
importergltf_test ();
|
||||||
importero3dv_test ();
|
|
||||||
importerobj_test ();
|
importerobj_test ();
|
||||||
importeroff_test ();
|
importeroff_test ();
|
||||||
importerply_test ();
|
importerply_test ();
|
||||||
|
|||||||
@ -1,136 +0,0 @@
|
|||||||
import * as assert from 'assert';
|
|
||||||
import * as OV from '../../source/engine/main.js';
|
|
||||||
import { ImportO3dvFile } from '../utils/testfiles.js';
|
|
||||||
import { ModelNodesToTree } from '../utils/testutils.js';
|
|
||||||
|
|
||||||
export default function suite ()
|
|
||||||
{
|
|
||||||
|
|
||||||
describe ('O3dv Importer', function () {
|
|
||||||
it ('translateandrotate.o3dv', function (done) {
|
|
||||||
ImportO3dvFile ('translateandrotate.o3dv', function (model) {
|
|
||||||
assert.ok (OV.CheckModel (model));
|
|
||||||
assert.deepStrictEqual (ModelNodesToTree (model), {
|
|
||||||
name : '<Root>',
|
|
||||||
childNodes : [
|
|
||||||
{
|
|
||||||
name : 'Translated',
|
|
||||||
childNodes : [
|
|
||||||
{
|
|
||||||
name : '',
|
|
||||||
childNodes : [],
|
|
||||||
meshNames : ['Cube']
|
|
||||||
}
|
|
||||||
],
|
|
||||||
meshNames : []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name : 'Rotated',
|
|
||||||
childNodes : [
|
|
||||||
{
|
|
||||||
name : 'Translated and Rotated',
|
|
||||||
childNodes : [
|
|
||||||
{
|
|
||||||
name : '',
|
|
||||||
childNodes : [],
|
|
||||||
meshNames : ['Cube']
|
|
||||||
}
|
|
||||||
],
|
|
||||||
meshNames : []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
meshNames : []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name : '',
|
|
||||||
childNodes : [],
|
|
||||||
meshNames : ['Cube']
|
|
||||||
}
|
|
||||||
],
|
|
||||||
meshNames : []
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.strictEqual (model.MeshInstanceCount (), 3);
|
|
||||||
let boundingBox = OV.GetBoundingBox (model);
|
|
||||||
assert.ok (OV.CoordIsEqual3D (boundingBox.min, new OV.Coord3D (-1.0, 0.0, 0.0)));
|
|
||||||
assert.ok (OV.CoordIsEqual3D (boundingBox.max, new OV.Coord3D (3.0, 3.0, 1.0)));
|
|
||||||
|
|
||||||
done ();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it ('solids.o3dv', function (done) {
|
|
||||||
ImportO3dvFile ('solids.o3dv', function (model) {
|
|
||||||
assert.ok (OV.CheckModel (model));
|
|
||||||
assert.deepStrictEqual (ModelNodesToTree (model), {
|
|
||||||
name : '<Root>',
|
|
||||||
childNodes : [
|
|
||||||
{
|
|
||||||
name : 'Tetrahedral',
|
|
||||||
childNodes : [
|
|
||||||
{
|
|
||||||
name : '',
|
|
||||||
childNodes : [],
|
|
||||||
meshNames : ['Tetrahedron']
|
|
||||||
}
|
|
||||||
],
|
|
||||||
meshNames : []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name : 'Octahedral',
|
|
||||||
childNodes : [
|
|
||||||
{
|
|
||||||
name : '',
|
|
||||||
childNodes : [],
|
|
||||||
meshNames : ['Hexahedron']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name : '',
|
|
||||||
childNodes : [],
|
|
||||||
meshNames : ['Octahedron']
|
|
||||||
}
|
|
||||||
],
|
|
||||||
meshNames : []
|
|
||||||
}, {
|
|
||||||
name : 'Icosahedral',
|
|
||||||
childNodes : [
|
|
||||||
{
|
|
||||||
name : '',
|
|
||||||
childNodes : [],
|
|
||||||
meshNames : ['Dodecahedron']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name : '',
|
|
||||||
childNodes : [],
|
|
||||||
meshNames : ['Icosahedron']
|
|
||||||
}
|
|
||||||
],
|
|
||||||
meshNames : []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
meshNames : []
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.strictEqual (model.MaterialCount (), 5);
|
|
||||||
assert.strictEqual (model.MeshCount (), 5);
|
|
||||||
assert.strictEqual (model.MeshInstanceCount (), 5);
|
|
||||||
|
|
||||||
assert.ok (OV.IsTwoManifold (model));
|
|
||||||
assert.ok (OV.IsEqual (OV.CalculateVolume (model), 8.707448863695035));
|
|
||||||
assert.ok (OV.IsEqual (OV.CalculateSurfaceArea (model), 39.636169009449105));
|
|
||||||
|
|
||||||
assert.strictEqual (model.PropertyGroupCount (), 1);
|
|
||||||
assert.strictEqual (model.GetPropertyGroup (0).PropertyCount (), 2);
|
|
||||||
|
|
||||||
for (let i = 0; i < model.MeshCount (); i++) {
|
|
||||||
let mesh = model.GetMesh (i);
|
|
||||||
assert.strictEqual (mesh.PropertyGroupCount (), 1);
|
|
||||||
assert.strictEqual (mesh.GetPropertyGroup (0).PropertyCount (), 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
done ();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -65,9 +65,3 @@ export function ImportGltfFile (folderName, fileName, onReady)
|
|||||||
var importer = new OV.ImporterGltf ();
|
var importer = new OV.ImporterGltf ();
|
||||||
ImportFile (importer, 'gltf/' + folderName, fileName, onReady);
|
ImportFile (importer, 'gltf/' + folderName, fileName, onReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ImportO3dvFile (fileName, onReady)
|
|
||||||
{
|
|
||||||
var importer = new OV.ImporterO3dv ();
|
|
||||||
ImportFile (importer, 'o3dv', fileName, onReady);
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user