Skip to content

Commit

Permalink
Merge branch 'support_lines' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacsv committed Nov 20, 2023
2 parents 97333a9 + 3022673 commit aed3193
Show file tree
Hide file tree
Showing 57 changed files with 1,483 additions and 307 deletions.
8 changes: 8 additions & 0 deletions docs/Class_EmbeddedViewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ <h2>Constructor</h2>
<div class="parameter_description">Default color of the model. It has effect only if the imported model doesn&#x27;t specify any color.</div>
</div>
<div class="parameter_header">
<span class="parameter_name">defaultLineColor</span>
<span class="type parameter_type"><a href="Class_RGBColor.html" target="_self">RGBColor</a></span>
<span class="parameter_attributes">(optional)</span>
</div>
<div class="parameter_main">
<div class="parameter_description">Default line color of the model. It has effect only if the imported model doesn&#x27;t specify any color.</div>
</div>
<div class="parameter_header">
<span class="parameter_name">edgeSettings</span>
<span class="type parameter_type"><a href="Class_EdgeSettings.html" target="_self">EdgeSettings</a></span>
<span class="parameter_attributes">(optional)</span>
Expand Down
61 changes: 61 additions & 0 deletions sandbox/embed_lines.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">

<title>Online 3D Viewer</title>

<script type="text/javascript" src="../build/engine_dev/o3dv.min.js"></script>

<script type='text/javascript'>
window.addEventListener ('load', () => {
OV.Init3DViewerElements ();
});
</script>

<style>
iframe, div.online_3d_viewer
{
float: left;
border: 1px solid #eeeeee;
margin: 0px 4px 4px 0px;
width: 360px;
height: 240px;
}
</style>
</head>

<body>
<iframe
src="../../website/embed.html#model=../test/testfiles/obj/cube_with_edges.obj">
</iframe>
<iframe
src="../../website/embed.html#model=../test/testfiles/obj/cube_with_edges.obj$defaultcolor=0,200,0$defaultlinecolor=0,100,0">
</iframe>
<iframe
src="../../website/embed.html#model=../test/testfiles/obj/cube_with_edges.obj,../test/testfiles/obj/cube_with_edges.mtl">
</iframe>
<iframe
src="../../website/embed.html#model=../test/testfiles/obj/cube_with_edges.obj,../test/testfiles/obj/cube_with_edges.mtl$defaultcolor=0,200,0$defaultlinecolor=0,100,0">
</iframe>
<div class="online_3d_viewer"
model="../test/testfiles/obj/cube_with_edges.obj">
</div>
<div class="online_3d_viewer"
model="../test/testfiles/obj/cube_with_edges.obj"
defaultcolor="0,200,0"
defaultlinecolor="0,100,0">
</div>
<div class="online_3d_viewer"
model="../test/testfiles/obj/cube_with_edges.obj,../test/testfiles/obj/cube_with_edges.mtl">
</div>
<div class="online_3d_viewer"
model="../test/testfiles/obj/cube_with_edges.obj,../test/testfiles/obj/cube_with_edges.mtl"
defaultcolor="0,200,0"
defaultlinecolor="0,100,0">
</div>
</body>

</html>
4 changes: 4 additions & 0 deletions source/engine/import/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class ImportSettings
{
constructor ()
{
this.defaultLineColor = new RGBColor (100, 100, 100);
this.defaultColor = new RGBColor (200, 200, 200);
}
}
Expand Down Expand Up @@ -215,6 +216,9 @@ export class Importer
});

importer.Import (mainFile.file.name, mainFile.file.extension, mainFile.file.content, {
getDefaultLineMaterialColor : () => {
return settings.defaultLineColor;
},
getDefaultMaterialColor : () => {
return settings.defaultColor;
},
Expand Down
97 changes: 75 additions & 22 deletions source/engine/import/importer3dm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { ConvertThreeGeometryToMesh } from '../threejs/threeutils.js';
import { ImporterBase } from './importerbase.js';
import { UpdateMaterialTransparency } from './importerutils.js';
import { TextureMap } from '../model/material.js';
import { Mesh } from '../model/mesh.js';
import { Line } from '../model/line.js';
import { ArrayToCoord3D } from '../geometry/coord3d.js';

export class Importer3dm extends ImporterBase
{
Expand Down Expand Up @@ -130,17 +133,16 @@ export class Importer3dm extends ImporterBase
return;
}

let rhinoMesh = null;
let deleteMesh = false;

if (objectType === this.rhino.ObjectType.Mesh) {
rhinoMesh = rhinoGeometry;
deleteMesh = false;
this.ImportRhinoGeometryAsMesh (rhinoDoc, rhinoGeometry, rhinoObject, rhinoInstanceReferences);
} else if (objectType === this.rhino.ObjectType.Extrusion) {
rhinoMesh = rhinoGeometry.getMesh (this.rhino.MeshType.Any);
deleteMesh = true;
let rhinoMesh = rhinoGeometry.getMesh (this.rhino.MeshType.Any);
if (rhinoMesh !== null) {
this.ImportRhinoGeometryAsMesh (rhinoDoc, rhinoMesh, rhinoObject, rhinoInstanceReferences);
rhinoMesh.delete ();
}
} else if (objectType === this.rhino.ObjectType.Brep) {
rhinoMesh = new this.rhino.Mesh ();
let rhinoMesh = new this.rhino.Mesh ();
let faces = rhinoGeometry.faces ();
for (let i = 0; i < faces.count; i++) {
let face = faces.get (i);
Expand All @@ -153,11 +155,17 @@ export class Importer3dm extends ImporterBase
}
faces.delete ();
rhinoMesh.compact ();
deleteMesh = true;
this.ImportRhinoGeometryAsMesh (rhinoDoc, rhinoMesh, rhinoObject, rhinoInstanceReferences);
rhinoMesh.delete ();
} else if (objectType === this.rhino.ObjectType.SubD) {
rhinoGeometry.subdivide (3);
rhinoMesh = this.rhino.Mesh.createFromSubDControlNet (rhinoGeometry);
deleteMesh = true;
let rhinoMesh = this.rhino.Mesh.createFromSubDControlNet (rhinoGeometry);
if (rhinoMesh !== null) {
this.ImportRhinoGeometryAsMesh (rhinoDoc, rhinoMesh, rhinoObject, rhinoInstanceReferences);
rhinoMesh.delete ();
}
} else if (objectType === this.rhino.ObjectType.Curve) {
this.ImportRhinoGeometryAsMesh (rhinoDoc, rhinoGeometry, rhinoObject, rhinoInstanceReferences);
} else if (objectType === this.rhino.ObjectType.InstanceReference) {
let parentDefinitionId = rhinoGeometry.parentIdefId;
if (this.instanceIdToDefinition.has (parentDefinitionId)) {
Expand All @@ -174,22 +182,58 @@ export class Importer3dm extends ImporterBase
}
}
}

if (rhinoMesh !== null) {
this.ImportRhinoMesh (rhinoDoc, rhinoMesh, rhinoObject, rhinoInstanceReferences);
if (deleteMesh) {
rhinoMesh.delete ();
}
}
}

ImportRhinoMesh (rhinoDoc, rhinoMesh, rhinoObject, rhinoInstanceReferences)
ImportRhinoGeometryAsMesh (rhinoDoc, rhinoGeometry, rhinoObject, rhinoInstanceReferences)
{
let rhinoAttributes = rhinoObject.attributes ();
function GetSegmentedCurveLine (curveGeometry)
{
let domainLength = curveGeometry.domain[1] - curveGeometry.domain[0];
let segmentCount = Math.max (parseInt (domainLength / 0.2, 10), 1);
let segmentLength = domainLength / segmentCount;
let vertices = [];
for (let i = 0; i <= segmentCount; i++) {
if (i === segmentCount && curveGeometry.isClosed) {
vertices.push (vertices[0]);
} else {
let position = rhinoGeometry.pointAt (curveGeometry.domain[0] + i * segmentLength);
vertices.push (mesh.AddVertex (ArrayToCoord3D (position)));
}
}
return new Line (vertices);
}

let materialIndex = this.GetMaterialIndex (rhinoDoc, rhinoObject, rhinoInstanceReferences);
let threeJson = rhinoMesh.toThreejsJSON ();
let mesh = ConvertThreeGeometryToMesh (threeJson.data, materialIndex, null);
let mesh = null;
if (rhinoGeometry.objectType === this.rhino.ObjectType.Mesh) {
let threeJson = rhinoGeometry.toThreejsJSON ();
mesh = ConvertThreeGeometryToMesh (threeJson.data, materialIndex, null);
} else if (rhinoGeometry.objectType === this.rhino.ObjectType.Curve) {
mesh = new Mesh ();
if (rhinoGeometry instanceof this.rhino.LineCurve) {
let fromVertex = mesh.AddVertex (ArrayToCoord3D (rhinoGeometry.line.from));
let toVertex = mesh.AddVertex (ArrayToCoord3D (rhinoGeometry.line.to));
let line = new Line ([fromVertex, toVertex]);
line.SetMaterial (materialIndex);
mesh.AddLine (line);
} else if (rhinoGeometry instanceof this.rhino.NurbsCurve) {
let line = GetSegmentedCurveLine (rhinoGeometry);
line.SetMaterial (materialIndex);
mesh.AddLine (line);
} else if (rhinoGeometry instanceof this.rhino.ArcCurve) {
let line = GetSegmentedCurveLine (rhinoGeometry);
line.SetMaterial (materialIndex);
mesh.AddLine (line);
}
}

// TODO: BezierCurve, PolyCurve

if (mesh === null) {
return null;
}

let rhinoAttributes = rhinoObject.attributes ();
mesh.SetName (rhinoAttributes.name);

let userStrings = rhinoAttributes.getUserStrings ();
Expand Down Expand Up @@ -234,6 +278,15 @@ export class Importer3dm extends ImporterBase
let layerMaterialIndex = layer.renderMaterialIndex;
if (layerMaterialIndex > -1) {
return rhinoDoc.materials ().get (layerMaterialIndex);
} else {
// use layer color only in case of curves
let rhinoGeometry = rhinoObject.geometry ();
if (rhinoGeometry.objectType === rhino.ObjectType.Curve) {
let material = new rhino.Material ();
material.name = layer.name;
material.diffuseColor = layer.color;
return material;
}
}
}
} else if (rhinoAttributes.materialSource === rhino.ObjectMaterialSource.MaterialFromParent) {
Expand Down
3 changes: 2 additions & 1 deletion source/engine/import/importerbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export class ImporterBase
}

FinalizeModel (this.model, {
getDefaultMaterialColor : this.callbacks.getDefaultMaterialColor
defaultLineMaterialColor : this.callbacks.getDefaultLineMaterialColor (),
defaultMaterialColor : this.callbacks.getDefaultMaterialColor ()
});

callbacks.onSuccess ();
Expand Down
Loading

0 comments on commit aed3193

Please sign in to comment.