Add sphere and empty test file.

This commit is contained in:
Viktor Kovacs 2021-05-02 12:23:02 +02:00
parent 8c468ba00d
commit cb348c657f
2 changed files with 20 additions and 3 deletions

Binary file not shown.

View File

@ -2,11 +2,17 @@ let rhino3dm = require ('../../../libs/rhino3dm.min.js')
let fs = require ('fs');
let path = require ('path');
function GetThreeMeshesFrom3dm (rhino, rhinoFileName)
function Open3dmFile (rhino, rhinoFileName)
{
let inputBuffer = fs.readFileSync (rhinoFileName, null).buffer;
let inputArray = new Uint8Array (inputBuffer);
let inputDoc = rhino.File3dm.fromByteArray (inputArray);
return inputDoc;
}
function GetThreeMeshesFrom3dm (rhino, rhinoFileName)
{
let inputDoc = Open3dmFile (rhino, rhinoFileName);
let objects = inputDoc.objects ();
let threeMeshes = [];
for (let i = 0; i < objects.count; i++) {
@ -33,9 +39,18 @@ function WriteThreeMeshesTo3dm (rhino, threeMeshes, rhinoFileName)
function ReadWriteRhinoFile (rhinoIn, rhinoOut, inputRhinoFile, outputRhinoFile)
{
let threeMeshes = GetThreeMeshesFrom3dm (rhinoIn, inputRhinoFile);
console.log ('Meshes in ' + inputRhinoFile + ': ' + threeMeshes.length);
let threeMeshes = [];
if (inputRhinoFile !== null) {
threeMeshes = GetThreeMeshesFrom3dm (rhinoIn, inputRhinoFile);
}
console.log ('Meshes in ' + outputRhinoFile + ': ' + threeMeshes.length);
WriteThreeMeshesTo3dm (rhinoOut, threeMeshes, outputRhinoFile);
let reopened = Open3dmFile (rhinoIn, outputRhinoFile);
if (reopened !== null) {
console.log ('SUCCESS');
} else {
console.log ('ERROR');
}
}
if (!fs.existsSync ('output')){
@ -47,5 +62,7 @@ rhino3dm ().then (async function (rhinoIn) {
ReadWriteRhinoFile (rhinoIn, rhinoOut, 'input/one_cube.3dm', 'output/one_cube.3dm');
ReadWriteRhinoFile (rhinoIn, rhinoOut, 'input/two_cubes.3dm', 'output/two_cubes.3dm');
ReadWriteRhinoFile (rhinoIn, rhinoOut, 'input/three_cubes.3dm', 'output/three_cubes.3dm');
ReadWriteRhinoFile (rhinoIn, rhinoOut, 'input/one_sphere.3dm', 'output/one_sphere.3dm');
ReadWriteRhinoFile (rhinoIn, rhinoOut, null, 'output/empty.3dm');
});
});