Skip to content

Commit aed3193

Browse files
committed
Merge branch 'support_lines' into dev
2 parents 97333a9 + 3022673 commit aed3193

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1483
-307
lines changed

docs/Class_EmbeddedViewer.html

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ <h2>Constructor</h2>
112112
<div class="parameter_description">Default color of the model. It has effect only if the imported model doesn&#x27;t specify any color.</div>
113113
</div>
114114
<div class="parameter_header">
115+
<span class="parameter_name">defaultLineColor</span>
116+
<span class="type parameter_type"><a href="Class_RGBColor.html" target="_self">RGBColor</a></span>
117+
<span class="parameter_attributes">(optional)</span>
118+
</div>
119+
<div class="parameter_main">
120+
<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>
121+
</div>
122+
<div class="parameter_header">
115123
<span class="parameter_name">edgeSettings</span>
116124
<span class="type parameter_type"><a href="Class_EdgeSettings.html" target="_self">EdgeSettings</a></span>
117125
<span class="parameter_attributes">(optional)</span>

sandbox/embed_lines.html

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta http-equiv="content-type" content="text/html;charset=utf-8">
6+
<meta name="viewport" content="width=device-width, user-scalable=no">
7+
8+
<title>Online 3D Viewer</title>
9+
10+
<script type="text/javascript" src="../build/engine_dev/o3dv.min.js"></script>
11+
12+
<script type='text/javascript'>
13+
window.addEventListener ('load', () => {
14+
OV.Init3DViewerElements ();
15+
});
16+
</script>
17+
18+
<style>
19+
iframe, div.online_3d_viewer
20+
{
21+
float: left;
22+
border: 1px solid #eeeeee;
23+
margin: 0px 4px 4px 0px;
24+
width: 360px;
25+
height: 240px;
26+
}
27+
</style>
28+
</head>
29+
30+
<body>
31+
<iframe
32+
src="../../website/embed.html#model=../test/testfiles/obj/cube_with_edges.obj">
33+
</iframe>
34+
<iframe
35+
src="../../website/embed.html#model=../test/testfiles/obj/cube_with_edges.obj$defaultcolor=0,200,0$defaultlinecolor=0,100,0">
36+
</iframe>
37+
<iframe
38+
src="../../website/embed.html#model=../test/testfiles/obj/cube_with_edges.obj,../test/testfiles/obj/cube_with_edges.mtl">
39+
</iframe>
40+
<iframe
41+
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">
42+
</iframe>
43+
<div class="online_3d_viewer"
44+
model="../test/testfiles/obj/cube_with_edges.obj">
45+
</div>
46+
<div class="online_3d_viewer"
47+
model="../test/testfiles/obj/cube_with_edges.obj"
48+
defaultcolor="0,200,0"
49+
defaultlinecolor="0,100,0">
50+
</div>
51+
<div class="online_3d_viewer"
52+
model="../test/testfiles/obj/cube_with_edges.obj,../test/testfiles/obj/cube_with_edges.mtl">
53+
</div>
54+
<div class="online_3d_viewer"
55+
model="../test/testfiles/obj/cube_with_edges.obj,../test/testfiles/obj/cube_with_edges.mtl"
56+
defaultcolor="0,200,0"
57+
defaultlinecolor="0,100,0">
58+
</div>
59+
</body>
60+
61+
</html>

source/engine/import/importer.js

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class ImportSettings
2121
{
2222
constructor ()
2323
{
24+
this.defaultLineColor = new RGBColor (100, 100, 100);
2425
this.defaultColor = new RGBColor (200, 200, 200);
2526
}
2627
}
@@ -215,6 +216,9 @@ export class Importer
215216
});
216217

217218
importer.Import (mainFile.file.name, mainFile.file.extension, mainFile.file.content, {
219+
getDefaultLineMaterialColor : () => {
220+
return settings.defaultLineColor;
221+
},
218222
getDefaultMaterialColor : () => {
219223
return settings.defaultColor;
220224
},

source/engine/import/importer3dm.js

+75-22
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { ConvertThreeGeometryToMesh } from '../threejs/threeutils.js';
1111
import { ImporterBase } from './importerbase.js';
1212
import { UpdateMaterialTransparency } from './importerutils.js';
1313
import { TextureMap } from '../model/material.js';
14+
import { Mesh } from '../model/mesh.js';
15+
import { Line } from '../model/line.js';
16+
import { ArrayToCoord3D } from '../geometry/coord3d.js';
1417

1518
export class Importer3dm extends ImporterBase
1619
{
@@ -130,17 +133,16 @@ export class Importer3dm extends ImporterBase
130133
return;
131134
}
132135

133-
let rhinoMesh = null;
134-
let deleteMesh = false;
135-
136136
if (objectType === this.rhino.ObjectType.Mesh) {
137-
rhinoMesh = rhinoGeometry;
138-
deleteMesh = false;
137+
this.ImportRhinoGeometryAsMesh (rhinoDoc, rhinoGeometry, rhinoObject, rhinoInstanceReferences);
139138
} else if (objectType === this.rhino.ObjectType.Extrusion) {
140-
rhinoMesh = rhinoGeometry.getMesh (this.rhino.MeshType.Any);
141-
deleteMesh = true;
139+
let rhinoMesh = rhinoGeometry.getMesh (this.rhino.MeshType.Any);
140+
if (rhinoMesh !== null) {
141+
this.ImportRhinoGeometryAsMesh (rhinoDoc, rhinoMesh, rhinoObject, rhinoInstanceReferences);
142+
rhinoMesh.delete ();
143+
}
142144
} else if (objectType === this.rhino.ObjectType.Brep) {
143-
rhinoMesh = new this.rhino.Mesh ();
145+
let rhinoMesh = new this.rhino.Mesh ();
144146
let faces = rhinoGeometry.faces ();
145147
for (let i = 0; i < faces.count; i++) {
146148
let face = faces.get (i);
@@ -153,11 +155,17 @@ export class Importer3dm extends ImporterBase
153155
}
154156
faces.delete ();
155157
rhinoMesh.compact ();
156-
deleteMesh = true;
158+
this.ImportRhinoGeometryAsMesh (rhinoDoc, rhinoMesh, rhinoObject, rhinoInstanceReferences);
159+
rhinoMesh.delete ();
157160
} else if (objectType === this.rhino.ObjectType.SubD) {
158161
rhinoGeometry.subdivide (3);
159-
rhinoMesh = this.rhino.Mesh.createFromSubDControlNet (rhinoGeometry);
160-
deleteMesh = true;
162+
let rhinoMesh = this.rhino.Mesh.createFromSubDControlNet (rhinoGeometry);
163+
if (rhinoMesh !== null) {
164+
this.ImportRhinoGeometryAsMesh (rhinoDoc, rhinoMesh, rhinoObject, rhinoInstanceReferences);
165+
rhinoMesh.delete ();
166+
}
167+
} else if (objectType === this.rhino.ObjectType.Curve) {
168+
this.ImportRhinoGeometryAsMesh (rhinoDoc, rhinoGeometry, rhinoObject, rhinoInstanceReferences);
161169
} else if (objectType === this.rhino.ObjectType.InstanceReference) {
162170
let parentDefinitionId = rhinoGeometry.parentIdefId;
163171
if (this.instanceIdToDefinition.has (parentDefinitionId)) {
@@ -174,22 +182,58 @@ export class Importer3dm extends ImporterBase
174182
}
175183
}
176184
}
177-
178-
if (rhinoMesh !== null) {
179-
this.ImportRhinoMesh (rhinoDoc, rhinoMesh, rhinoObject, rhinoInstanceReferences);
180-
if (deleteMesh) {
181-
rhinoMesh.delete ();
182-
}
183-
}
184185
}
185186

186-
ImportRhinoMesh (rhinoDoc, rhinoMesh, rhinoObject, rhinoInstanceReferences)
187+
ImportRhinoGeometryAsMesh (rhinoDoc, rhinoGeometry, rhinoObject, rhinoInstanceReferences)
187188
{
188-
let rhinoAttributes = rhinoObject.attributes ();
189+
function GetSegmentedCurveLine (curveGeometry)
190+
{
191+
let domainLength = curveGeometry.domain[1] - curveGeometry.domain[0];
192+
let segmentCount = Math.max (parseInt (domainLength / 0.2, 10), 1);
193+
let segmentLength = domainLength / segmentCount;
194+
let vertices = [];
195+
for (let i = 0; i <= segmentCount; i++) {
196+
if (i === segmentCount && curveGeometry.isClosed) {
197+
vertices.push (vertices[0]);
198+
} else {
199+
let position = rhinoGeometry.pointAt (curveGeometry.domain[0] + i * segmentLength);
200+
vertices.push (mesh.AddVertex (ArrayToCoord3D (position)));
201+
}
202+
}
203+
return new Line (vertices);
204+
}
189205

190206
let materialIndex = this.GetMaterialIndex (rhinoDoc, rhinoObject, rhinoInstanceReferences);
191-
let threeJson = rhinoMesh.toThreejsJSON ();
192-
let mesh = ConvertThreeGeometryToMesh (threeJson.data, materialIndex, null);
207+
let mesh = null;
208+
if (rhinoGeometry.objectType === this.rhino.ObjectType.Mesh) {
209+
let threeJson = rhinoGeometry.toThreejsJSON ();
210+
mesh = ConvertThreeGeometryToMesh (threeJson.data, materialIndex, null);
211+
} else if (rhinoGeometry.objectType === this.rhino.ObjectType.Curve) {
212+
mesh = new Mesh ();
213+
if (rhinoGeometry instanceof this.rhino.LineCurve) {
214+
let fromVertex = mesh.AddVertex (ArrayToCoord3D (rhinoGeometry.line.from));
215+
let toVertex = mesh.AddVertex (ArrayToCoord3D (rhinoGeometry.line.to));
216+
let line = new Line ([fromVertex, toVertex]);
217+
line.SetMaterial (materialIndex);
218+
mesh.AddLine (line);
219+
} else if (rhinoGeometry instanceof this.rhino.NurbsCurve) {
220+
let line = GetSegmentedCurveLine (rhinoGeometry);
221+
line.SetMaterial (materialIndex);
222+
mesh.AddLine (line);
223+
} else if (rhinoGeometry instanceof this.rhino.ArcCurve) {
224+
let line = GetSegmentedCurveLine (rhinoGeometry);
225+
line.SetMaterial (materialIndex);
226+
mesh.AddLine (line);
227+
}
228+
}
229+
230+
// TODO: BezierCurve, PolyCurve
231+
232+
if (mesh === null) {
233+
return null;
234+
}
235+
236+
let rhinoAttributes = rhinoObject.attributes ();
193237
mesh.SetName (rhinoAttributes.name);
194238

195239
let userStrings = rhinoAttributes.getUserStrings ();
@@ -234,6 +278,15 @@ export class Importer3dm extends ImporterBase
234278
let layerMaterialIndex = layer.renderMaterialIndex;
235279
if (layerMaterialIndex > -1) {
236280
return rhinoDoc.materials ().get (layerMaterialIndex);
281+
} else {
282+
// use layer color only in case of curves
283+
let rhinoGeometry = rhinoObject.geometry ();
284+
if (rhinoGeometry.objectType === rhino.ObjectType.Curve) {
285+
let material = new rhino.Material ();
286+
material.name = layer.name;
287+
material.diffuseColor = layer.color;
288+
return material;
289+
}
237290
}
238291
}
239292
} else if (rhinoAttributes.materialSource === rhino.ObjectMaterialSource.MaterialFromParent) {

source/engine/import/importerbase.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export class ImporterBase
5858
}
5959

6060
FinalizeModel (this.model, {
61-
getDefaultMaterialColor : this.callbacks.getDefaultMaterialColor
61+
defaultLineMaterialColor : this.callbacks.getDefaultLineMaterialColor (),
62+
defaultMaterialColor : this.callbacks.getDefaultMaterialColor ()
6263
});
6364

6465
callbacks.onSuccess ();

0 commit comments

Comments
 (0)