Add o3dv file format for testing purposes.

This commit is contained in:
Viktor Kovacs 2021-05-27 20:20:00 +02:00
parent 93b084f20a
commit a3d283f613
18 changed files with 359 additions and 3 deletions

View File

@ -44,6 +44,7 @@
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>

View File

@ -45,6 +45,7 @@
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>

View File

@ -44,6 +44,7 @@
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>

View File

@ -44,6 +44,7 @@
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>

View File

@ -265,7 +265,8 @@ OV.Importer = class
new OV.ImporterOff (),
new OV.ImporterPly (),
new OV.Importer3ds (),
new OV.ImporterGltf ()
new OV.ImporterGltf (),
new OV.ImporterO3dv ()
];
this.fileList = new OV.FileList (this.importers);
this.model = null;

View File

@ -0,0 +1,104 @@
OV.ImporterO3dv = class extends OV.ImporterBase
{
constructor ()
{
super ();
}
CanImportExtension (extension)
{
return extension === 'o3dv';
}
GetKnownFileFormats ()
{
return {
'o3dv' : OV.FileFormat.Text
};
}
GetUpDirection ()
{
return OV.Direction.Z;
}
ClearContent ()
{
}
ResetContent ()
{
}
ImportContent (fileContent, onFinish)
{
let content = JSON.parse (fileContent);
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);
}
}
onFinish ();
}
ImportMaterial (materialContent)
{
let material = new OV.Material ();
material.diffuse.Set (255, 255, 255);
if (materialContent.name !== undefined) {
material.name = materialContent.name;
}
if (materialContent.diffuse !== undefined) {
material.diffuse = OV.ArrayToColor (materialContent.diffuse);
}
this.model.AddMaterial (material);
}
ImportMesh (meshContent)
{
let genParams = new OV.GeneratorParams ();
if (meshContent.name !== undefined) {
genParams.SetName (meshContent.name);
}
if (meshContent.material !== undefined) {
genParams.SetMaterial (meshContent.material);
}
if (meshContent.transformation !== undefined) {
let translation = new OV.Coord3D (0.0, 0.0, 0.0);
let rotation = new OV.Quaternion (0.0, 0.0, 0.0, 1.0);
let scale = new OV.Coord3D (1.0, 1.0, 1.0);
if (meshContent.transformation.translation !== undefined) {
translation = OV.ArrayToCoord3D (meshContent.transformation.translation);
}
if (meshContent.transformation.rotation !== undefined) {
rotation = OV.ArrayToQuaternion (meshContent.transformation.rotation);
}
if (meshContent.transformation.scale !== undefined) {
scale = OV.ArrayToCoord3D (meshContent.transformation.scale);
}
genParams.SetTransformation (translation, rotation, scale);
}
let parameters = meshContent.parameters;
if (parameters === undefined) {
return;
}
if (meshContent.type === 'cuboid') {
if (parameters.size_x === undefined || parameters.size_y === undefined || parameters.size_z === undefined) {
return;
}
const mesh = OV.GenerateCuboid (genParams, parameters.size_x, parameters.size_y, parameters.size_z);
this.model.AddMesh (mesh);
}
}
};

View File

@ -24,7 +24,6 @@ OV.ImporterOff = class extends OV.ImporterBase
ClearContent ()
{
this.model = null;
this.mesh = null;
this.status = null;
}

View File

@ -110,7 +110,6 @@ OV.ImporterPly = class extends OV.ImporterBase
ClearContent ()
{
this.model = null;
this.mesh = null;
}

View File

@ -2,10 +2,17 @@ OV.GeneratorParams = class
{
constructor ()
{
this.name = null;
this.material = null;
this.transformation = null;
}
SetName (name)
{
this.name = name;
return this;
}
SetMaterial (material)
{
this.material = material;
@ -31,6 +38,9 @@ OV.Generator = class
{
this.params = params || new OV.GeneratorParams ();
this.mesh = new OV.Mesh ();
if (this.params.name !== null) {
this.mesh.SetName (this.params.name);
}
}
GetMesh ()

View File

@ -195,3 +195,8 @@ OV.ColorIsEqual = function (a, b)
{
return a.r === b.r && a.g === b.g && a.b === b.b;
};
OV.ArrayToColor = function (arr)
{
return new OV.Color (arr[0], arr[1], arr[2]);
};

View File

@ -0,0 +1,12 @@
{
"meshes" : [
{
"type" : "cuboid",
"parameters" : {
"size_x" : 1.0,
"size_y" : 1.0,
"size_z" : 1.0
}
}
]
}

View File

@ -0,0 +1,74 @@
{
"materials" : [
{
"name" : "Material 1",
"diffuse" : [200, 0, 0]
},
{
"name" : "Material 2",
"diffuse" : [0, 200, 0]
},
{
"name" : "Material 3",
"diffuse" : [0, 0, 200]
},
{
"name" : "Material 4",
"diffuse" : [200, 200, 0]
}
],
"meshes" : [
{
"name" : "Cube",
"material" : 0,
"type" : "cuboid",
"parameters" : {
"size_x" : 1.0,
"size_y" : 1.0,
"size_z" : 1.0
}
},
{
"name" : "Cube T",
"material" : 1,
"transformation" : {
"translation" : [2.0, 0.0, 0.0]
},
"type" : "cuboid",
"parameters" : {
"size_x" : 1.0,
"size_y" : 1.0,
"size_z" : 1.0
}
},
{
"name" : "Cube TR",
"material" : 2,
"transformation" : {
"translation" : [4.0, 0.0, 0.0],
"rotation" : [0.0, 0.0, 0.3826834323650898, 0.9238795325112867]
},
"type" : "cuboid",
"parameters" : {
"size_x" : 1.0,
"size_y" : 1.0,
"size_z" : 1.0
}
},
{
"name" : "Cube TRS",
"material" : 3,
"transformation" : {
"translation" : [6.0, 0.0, 0.0],
"rotation" : [0.0, 0.0, 0.3826834323650898, 0.9238795325112867],
"scale" : [1.5, 2.0, 2.5]
},
"type" : "cuboid",
"parameters" : {
"size_x" : 1.0,
"size_y" : 1.0,
"size_z" : 1.0
}
}
]
}

View File

@ -0,0 +1,20 @@
{
"materials" : [
{
"name" : "Material",
"diffuse" : [200, 0, 0]
}
],
"meshes" : [
{
"name" : "Cube",
"material" : 0,
"type" : "cuboid",
"parameters" : {
"size_x" : 1.0,
"size_y" : 1.0,
"size_z" : 1.0
}
}
]
}

View File

@ -0,0 +1,119 @@
var assert = require ('assert');
var testFiles = require ('../utils/testfiles.js');
var testUtils = require ('../utils/testutils.js');
describe ('O3dv Importer', function () {
it ('cube.o3dv', function (done) {
testFiles.ImportO3dvFile ('cube.o3dv', function (model) {
assert (OV.CheckModel (model));
assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), {
name : '',
materials : [
{ name : '' }
],
meshes : [
{
name : '',
vertexCount : 8,
normalCount : 12,
uvCount : 0,
triangleCount : 12,
boundingBox : {
min : [0, 0, 0],
max : [1, 1, 1]
}
}
]
});
done ();
});
});
it ('cube_with_material.o3dv', function (done) {
testFiles.ImportO3dvFile ('cube_with_material.o3dv', function (model) {
assert (OV.CheckModel (model));
assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), {
name : '',
materials : [
{ name : 'Material' }
],
meshes : [
{
name : 'Cube',
vertexCount : 8,
normalCount : 12,
uvCount : 0,
triangleCount : 12,
boundingBox : {
min : [0, 0, 0],
max : [1, 1, 1]
}
}
]
});
done ();
});
});
it ('cube_transformation.o3dv', function (done) {
testFiles.ImportO3dvFile ('cube_transformation.o3dv', function (model) {
assert (OV.CheckModel (model));
assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), {
name : '',
materials : [
{ name : 'Material 1' },
{ name : 'Material 2' },
{ name : 'Material 3' },
{ name : 'Material 4' }
],
meshes : [
{
name : 'Cube',
vertexCount : 8,
normalCount : 12,
uvCount : 0,
triangleCount : 12,
boundingBox : {
min : [0, 0, 0],
max : [1, 1, 1]
}
},
{
name : 'Cube T',
vertexCount : 8,
normalCount : 12,
uvCount : 0,
triangleCount : 12,
boundingBox : {
min : [2, 0, 0],
max : [3, 1, 1]
}
},
{
name : 'Cube TR',
vertexCount : 8,
normalCount : 12,
uvCount : 0,
triangleCount : 12,
boundingBox : {
min : [3.2928932188134525, 0, 0],
max : [4.707106781186548, 1.414213562373095, 1]
}
},
{
name : 'Cube TRS',
vertexCount : 8,
normalCount : 12,
uvCount : 0,
triangleCount : 12,
boundingBox : {
min : [4.585786437626905, 0, 0],
max : [7.060660171779821, 2.4748737341529163, 2.5]
}
}
]
});
done ();
});
});
});

View File

@ -43,6 +43,12 @@ module.exports =
this.ImportFile (importer, format, 'gltf/' + folderName, fileName, onReady);
},
ImportO3dvFile : function (fileName, onReady)
{
var importer = new OV.ImporterO3dv ();
this.ImportFile (importer, OV.FileFormat.Text, 'o3dv', fileName, onReady);
},
ImportFile : function (importer, format, folder, fileName, onReady)
{
var content = null;

View File

@ -40,6 +40,7 @@
"source/import/importerply.js",
"source/import/importer3ds.js",
"source/import/importergltf.js",
"source/import/importero3dv.js",
"source/import/importer.js",
"source/export/exporterbase.js",
"source/export/exporterobj.js",

View File

@ -53,6 +53,7 @@
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>

View File

@ -53,6 +53,7 @@
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>