Merge branch 'support_lines' into dev
This commit is contained in:
commit
aed31939fd
@ -112,6 +112,14 @@
|
||||
<div class="parameter_description">Default color of the model. It has effect only if the imported model doesn'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'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>
|
||||
|
||||
61
sandbox/embed_lines.html
Normal file
61
sandbox/embed_lines.html
Normal file
@ -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>
|
||||
@ -21,6 +21,7 @@ export class ImportSettings
|
||||
{
|
||||
constructor ()
|
||||
{
|
||||
this.defaultLineColor = new RGBColor (100, 100, 100);
|
||||
this.defaultColor = new RGBColor (200, 200, 200);
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
},
|
||||
|
||||
@ -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
|
||||
{
|
||||
@ -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);
|
||||
@ -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)) {
|
||||
@ -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 ();
|
||||
@ -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) {
|
||||
|
||||
@ -58,7 +58,8 @@ export class ImporterBase
|
||||
}
|
||||
|
||||
FinalizeModel (this.model, {
|
||||
getDefaultMaterialColor : this.callbacks.getDefaultMaterialColor
|
||||
defaultLineMaterialColor : this.callbacks.getDefaultLineMaterialColor (),
|
||||
defaultMaterialColor : this.callbacks.getDefaultMaterialColor ()
|
||||
});
|
||||
|
||||
callbacks.onSuccess ();
|
||||
|
||||
@ -2,6 +2,7 @@ import { Coord2D } from '../geometry/coord2d.js';
|
||||
import { Coord3D } from '../geometry/coord3d.js';
|
||||
import { Direction } from '../geometry/geometry.js';
|
||||
import { ArrayBufferToUtf8String } from '../io/bufferutils.js';
|
||||
import { Line } from '../model/line.js';
|
||||
import { RGBColor, RGBColorFromFloatComponents } from '../model/color.js';
|
||||
import { PhongMaterial, TextureMap } from '../model/material.js';
|
||||
import { Mesh } from '../model/mesh.js';
|
||||
@ -22,38 +23,43 @@ class ObjMeshConverter
|
||||
|
||||
AddVertex (globalIndex, globalVertices)
|
||||
{
|
||||
return this.GetLocalIndex (globalIndex, globalVertices, this.globalToMeshVertices, (val) => {
|
||||
return this.GetMeshIndex (globalIndex, globalVertices, this.globalToMeshVertices, (val) => {
|
||||
return this.mesh.AddVertex (new Coord3D (val.x, val.y, val.z));
|
||||
});
|
||||
}
|
||||
|
||||
AddVertexColor (globalIndex, globalVertexColors)
|
||||
{
|
||||
return this.GetLocalIndex (globalIndex, globalVertexColors, this.globalToMeshVertexColors, (val) => {
|
||||
return this.GetMeshIndex (globalIndex, globalVertexColors, this.globalToMeshVertexColors, (val) => {
|
||||
return this.mesh.AddVertexColor (new RGBColor (val.r, val.g, val.b));
|
||||
});
|
||||
}
|
||||
|
||||
AddNormal (globalIndex, globalNormals)
|
||||
{
|
||||
return this.GetLocalIndex (globalIndex, globalNormals, this.globalToMeshNormals, (val) => {
|
||||
return this.GetMeshIndex (globalIndex, globalNormals, this.globalToMeshNormals, (val) => {
|
||||
return this.mesh.AddNormal (new Coord3D (val.x, val.y, val.z));
|
||||
});
|
||||
}
|
||||
|
||||
AddUV (globalIndex, globalUvs)
|
||||
{
|
||||
return this.GetLocalIndex (globalIndex, globalUvs, this.globalToMeshUvs, (val) => {
|
||||
return this.GetMeshIndex (globalIndex, globalUvs, this.globalToMeshUvs, (val) => {
|
||||
return this.mesh.AddTextureUV (new Coord2D (val.x, val.y));
|
||||
});
|
||||
}
|
||||
|
||||
AddLine (line)
|
||||
{
|
||||
this.mesh.AddLine (line);
|
||||
}
|
||||
|
||||
AddTriangle (triangle)
|
||||
{
|
||||
this.mesh.AddTriangle (triangle);
|
||||
}
|
||||
|
||||
GetLocalIndex (globalIndex, globalValueArray, globalToMeshIndices, valueAdderFunc)
|
||||
GetMeshIndex (globalIndex, globalValueArray, globalToMeshIndices, valueAdderFunc)
|
||||
{
|
||||
if (isNaN (globalIndex) || globalIndex < 0 || globalIndex >= globalValueArray.length) {
|
||||
return null;
|
||||
@ -62,9 +68,9 @@ class ObjMeshConverter
|
||||
return globalToMeshIndices.get (globalIndex);
|
||||
} else {
|
||||
let globalValue = globalValueArray[globalIndex];
|
||||
let localIndex = valueAdderFunc (globalValue);
|
||||
globalToMeshIndices.set (globalIndex, localIndex);
|
||||
return localIndex;
|
||||
let meshIndex = valueAdderFunc (globalValue);
|
||||
globalToMeshIndices.set (globalIndex, meshIndex);
|
||||
return meshIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -213,11 +219,16 @@ export class ImporterObj extends ImporterBase
|
||||
parseFloat (parameters[1])
|
||||
));
|
||||
return true;
|
||||
} else if (keyword === 'l') {
|
||||
if (parameters.length < 2) {
|
||||
return true;
|
||||
}
|
||||
this.ProcessLineCommand (parameters);
|
||||
} else if (keyword === 'f') {
|
||||
if (parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.ProcessFace (parameters);
|
||||
this.ProcessFaceCommand (parameters);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -375,40 +386,57 @@ export class ImporterObj extends ImporterBase
|
||||
return false;
|
||||
}
|
||||
|
||||
ProcessFace (parameters)
|
||||
ProcessLineCommand (parameters)
|
||||
{
|
||||
function GetRelativeIndex (index, count)
|
||||
{
|
||||
if (index > 0) {
|
||||
return index - 1;
|
||||
} else {
|
||||
return count + index;
|
||||
}
|
||||
if (this.currentMeshConverter === null) {
|
||||
this.AddNewMesh ('');
|
||||
}
|
||||
|
||||
let vertices = [];
|
||||
for (let i = 0; i < parameters.length; i++) {
|
||||
let vertexParams = parameters[i].split ('/');
|
||||
let vertexIndex = this.GetRelativeIndex (parseInt (vertexParams[0], 10), this.globalVertices.length);
|
||||
let meshVertexIndex = this.currentMeshConverter.AddVertex (vertexIndex, this.globalVertices);
|
||||
if (meshVertexIndex === null) {
|
||||
this.SetError ('Invalid vertex index.');
|
||||
break;
|
||||
}
|
||||
vertices.push (meshVertexIndex);
|
||||
}
|
||||
|
||||
let line = new Line (vertices);
|
||||
if (this.currentMaterialIndex !== null) {
|
||||
line.mat = this.currentMaterialIndex;
|
||||
}
|
||||
|
||||
this.currentMeshConverter.AddLine (line);
|
||||
}
|
||||
|
||||
ProcessFaceCommand (parameters)
|
||||
{
|
||||
let vertices = [];
|
||||
let colors = [];
|
||||
let normals = [];
|
||||
let uvs = [];
|
||||
|
||||
for (let i = 0; i < parameters.length; i++) {
|
||||
let vertexParams = parameters[i].split ('/');
|
||||
vertices.push (GetRelativeIndex (parseInt (vertexParams[0], 10), this.globalVertices.length));
|
||||
if (this.globalVertices.length === this.globalVertexColors.length) {
|
||||
colors.push (GetRelativeIndex (parseInt (vertexParams[0], 10), this.globalVertices.length));
|
||||
}
|
||||
if (vertexParams.length > 1 && vertexParams[1].length > 0) {
|
||||
uvs.push (GetRelativeIndex (parseInt (vertexParams[1], 10), this.globalUvs.length));
|
||||
}
|
||||
if (vertexParams.length > 2 && vertexParams[2].length > 0) {
|
||||
normals.push (GetRelativeIndex (parseInt (vertexParams[2], 10), this.globalNormals.length));
|
||||
}
|
||||
}
|
||||
|
||||
if (this.currentMeshConverter === null) {
|
||||
this.AddNewMesh ('');
|
||||
}
|
||||
|
||||
for (let i = 0; i < parameters.length; i++) {
|
||||
let vertexParams = parameters[i].split ('/');
|
||||
vertices.push (this.GetRelativeIndex (parseInt (vertexParams[0], 10), this.globalVertices.length));
|
||||
if (this.globalVertices.length === this.globalVertexColors.length) {
|
||||
colors.push (this.GetRelativeIndex (parseInt (vertexParams[0], 10), this.globalVertices.length));
|
||||
}
|
||||
if (vertexParams.length > 1 && vertexParams[1].length > 0) {
|
||||
uvs.push (this.GetRelativeIndex (parseInt (vertexParams[1], 10), this.globalUvs.length));
|
||||
}
|
||||
if (vertexParams.length > 2 && vertexParams[2].length > 0) {
|
||||
normals.push (this.GetRelativeIndex (parseInt (vertexParams[2], 10), this.globalNormals.length));
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < vertices.length - 2; i++) {
|
||||
let v0 = this.currentMeshConverter.AddVertex (vertices[0], this.globalVertices);
|
||||
let v1 = this.currentMeshConverter.AddVertex (vertices[i + 1], this.globalVertices);
|
||||
@ -460,4 +488,13 @@ export class ImporterObj extends ImporterBase
|
||||
this.currentMeshConverter.AddTriangle (triangle);
|
||||
}
|
||||
}
|
||||
|
||||
GetRelativeIndex (index, count)
|
||||
{
|
||||
if (index > 0) {
|
||||
return index - 1;
|
||||
} else {
|
||||
return count + index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,14 +46,15 @@ import { GetFileName, GetFileExtension, RequestUrl, ReadFile, TransformFileHostU
|
||||
import { TextWriter } from './io/textwriter.js';
|
||||
import { RGBColor, RGBAColor, ColorComponentFromFloat, ColorComponentToFloat, RGBColorFromFloatComponents, SRGBToLinear, LinearToSRGB, IntegerToHexString, RGBColorToHexString, RGBAColorToHexString, HexStringToRGBColor, HexStringToRGBAColor, ArrayToRGBColor, RGBColorIsEqual } from './model/color.js';
|
||||
import { GeneratorParams, Generator, GeneratorHelper, GenerateCuboid, GenerateCone, GenerateCylinder, GenerateSphere, GeneratePlatonicSolid } from './model/generator.js';
|
||||
import { TextureMap, MaterialBase, FaceMaterial, PhongMaterial, PhysicalMaterial, TextureMapIsEqual, TextureIsEqual, MaterialType } from './model/material.js';
|
||||
import { Line } from './model/line.js';
|
||||
import { TextureMap, MaterialBase, FaceMaterial, PhongMaterial, PhysicalMaterial, TextureMapIsEqual, TextureIsEqual, MaterialType, MaterialSource } from './model/material.js';
|
||||
import { Mesh } from './model/mesh.js';
|
||||
import { MeshPrimitiveBuffer, MeshBuffer, ConvertMeshToMeshBuffer } from './model/meshbuffer.js';
|
||||
import { MeshInstanceId, MeshInstance } from './model/meshinstance.js';
|
||||
import { GetMeshType, CalculateTriangleNormal, TransformMesh, FlipMeshTrianglesOrientation, MeshType } from './model/meshutils.js';
|
||||
import { IsEmptyMesh, CalculateTriangleNormal, TransformMesh, FlipMeshTrianglesOrientation } from './model/meshutils.js';
|
||||
import { Model } from './model/model.js';
|
||||
import { FinalizeModel, CheckModel } from './model/modelfinalization.js';
|
||||
import { IsModelEmpty, GetBoundingBox, GetTopology, IsTwoManifold, HasDefaultMaterial, ReplaceDefaultMaterialColor } from './model/modelutils.js';
|
||||
import { IsModelEmpty, GetBoundingBox, GetTopology, IsTwoManifold, GetDefaultMaterials, ReplaceDefaultMaterialsColor } from './model/modelutils.js';
|
||||
import { Node } from './model/node.js';
|
||||
import { Object3D, ModelObject3D } from './model/object.js';
|
||||
import { Property, PropertyGroup, PropertyToString, PropertyType } from './model/property.js';
|
||||
@ -62,9 +63,9 @@ import { TopologyVertex, TopologyEdge, TopologyTriangleEdge, TopologyTriangle, T
|
||||
import { Triangle } from './model/triangle.js';
|
||||
import { Unit } from './model/unit.js';
|
||||
import { ParameterListBuilder, ParameterListParser, CreateUrlBuilder, CreateUrlParser, CreateModelUrlParameters, ParameterConverter } from './parameters/parameterlist.js';
|
||||
import { ModelToThreeConversionParams, ModelToThreeConversionOutput, ThreeConversionStateHandler, ThreeNodeTree, ConvertModelToThreeObject } from './threejs/threeconverter.js';
|
||||
import { ModelToThreeConversionParams, ModelToThreeConversionOutput, ThreeConversionStateHandler, ThreeNodeTree, ThreeMaterialHandler, ThreeMeshMaterialHandler, ConvertModelToThreeObject, MaterialGeometryType } from './threejs/threeconverter.js';
|
||||
import { ThreeModelLoader } from './threejs/threemodelloader.js';
|
||||
import { ThreeColorConverter, ThreeLinearToSRGBColorConverter, ThreeSRGBToLinearColorConverter, HasHighpDriverIssue, GetShadingType, ConvertThreeColorToColor, ConvertColorToThreeColor, ConvertThreeGeometryToMesh, DisposeThreeObjects, ShadingType } from './threejs/threeutils.js';
|
||||
import { ThreeColorConverter, ThreeLinearToSRGBColorConverter, ThreeSRGBToLinearColorConverter, HasHighpDriverIssue, GetShadingType, ConvertThreeColorToColor, ConvertColorToThreeColor, ConvertThreeGeometryToMesh, CreateHighlightMaterial, CreateHighlightMaterials, DisposeThreeObjects, ShadingType } from './threejs/threeutils.js';
|
||||
import { Camera, CameraIsEqual3D, NavigationMode, ProjectionMode } from './viewer/camera.js';
|
||||
import { GetIntegerFromStyle, GetDomElementExternalWidth, GetDomElementExternalHeight, GetDomElementInnerDimensions, GetDomElementClientCoordinates, CreateDomElement, AddDomElement, AddDiv, ClearDomElement, InsertDomElementBefore, InsertDomElementAfter, ShowDomElement, IsDomElementVisible, SetDomElementWidth, SetDomElementHeight, GetDomElementOuterWidth, GetDomElementOuterHeight, SetDomElementOuterWidth, SetDomElementOuterHeight, CreateDiv } from './viewer/domutils.js';
|
||||
import { EmbeddedViewer, Init3DViewerFromUrlList, Init3DViewerFromFileList, Init3DViewerElements } from './viewer/embeddedviewer.js';
|
||||
@ -226,6 +227,7 @@ export {
|
||||
GenerateCylinder,
|
||||
GenerateSphere,
|
||||
GeneratePlatonicSolid,
|
||||
Line,
|
||||
TextureMap,
|
||||
MaterialBase,
|
||||
FaceMaterial,
|
||||
@ -234,17 +236,17 @@ export {
|
||||
TextureMapIsEqual,
|
||||
TextureIsEqual,
|
||||
MaterialType,
|
||||
MaterialSource,
|
||||
Mesh,
|
||||
MeshPrimitiveBuffer,
|
||||
MeshBuffer,
|
||||
ConvertMeshToMeshBuffer,
|
||||
MeshInstanceId,
|
||||
MeshInstance,
|
||||
GetMeshType,
|
||||
IsEmptyMesh,
|
||||
CalculateTriangleNormal,
|
||||
TransformMesh,
|
||||
FlipMeshTrianglesOrientation,
|
||||
MeshType,
|
||||
Model,
|
||||
FinalizeModel,
|
||||
CheckModel,
|
||||
@ -252,8 +254,8 @@ export {
|
||||
GetBoundingBox,
|
||||
GetTopology,
|
||||
IsTwoManifold,
|
||||
HasDefaultMaterial,
|
||||
ReplaceDefaultMaterialColor,
|
||||
GetDefaultMaterials,
|
||||
ReplaceDefaultMaterialsColor,
|
||||
Node,
|
||||
Object3D,
|
||||
ModelObject3D,
|
||||
@ -282,7 +284,10 @@ export {
|
||||
ModelToThreeConversionOutput,
|
||||
ThreeConversionStateHandler,
|
||||
ThreeNodeTree,
|
||||
ThreeMaterialHandler,
|
||||
ThreeMeshMaterialHandler,
|
||||
ConvertModelToThreeObject,
|
||||
MaterialGeometryType,
|
||||
ThreeModelLoader,
|
||||
ThreeColorConverter,
|
||||
ThreeLinearToSRGBColorConverter,
|
||||
@ -292,6 +297,8 @@ export {
|
||||
ConvertThreeColorToColor,
|
||||
ConvertColorToThreeColor,
|
||||
ConvertThreeGeometryToMesh,
|
||||
CreateHighlightMaterial,
|
||||
CreateHighlightMaterials,
|
||||
DisposeThreeObjects,
|
||||
ShadingType,
|
||||
Camera,
|
||||
|
||||
39
source/engine/model/line.js
Normal file
39
source/engine/model/line.js
Normal file
@ -0,0 +1,39 @@
|
||||
export class Line
|
||||
{
|
||||
constructor (vertices)
|
||||
{
|
||||
this.vertices = vertices;
|
||||
this.mat = null;
|
||||
}
|
||||
|
||||
HasVertices ()
|
||||
{
|
||||
return this.vertices !== null && this.vertices.length >= 2;
|
||||
}
|
||||
|
||||
GetVertices ()
|
||||
{
|
||||
return this.vertices;
|
||||
}
|
||||
|
||||
SetMaterial (mat)
|
||||
{
|
||||
this.mat = mat;
|
||||
return this;
|
||||
}
|
||||
|
||||
SegmentCount ()
|
||||
{
|
||||
if (this.vertices === null) {
|
||||
return 0;
|
||||
}
|
||||
return this.vertices.length - 1;
|
||||
}
|
||||
|
||||
Clone ()
|
||||
{
|
||||
let cloned = new Line ([...this.vertices]);
|
||||
cloned.SetMaterial (this.mat);
|
||||
return cloned;
|
||||
}
|
||||
}
|
||||
@ -70,12 +70,19 @@ export const MaterialType =
|
||||
Physical : 2
|
||||
};
|
||||
|
||||
export const MaterialSource =
|
||||
{
|
||||
Model : 1,
|
||||
DefaultFace : 2,
|
||||
DefaultLine : 3
|
||||
};
|
||||
|
||||
export class MaterialBase
|
||||
{
|
||||
constructor (type)
|
||||
{
|
||||
this.type = type;
|
||||
this.isDefault = false;
|
||||
this.source = MaterialSource.Model;
|
||||
|
||||
this.name = '';
|
||||
this.color = new RGBColor (0, 0, 0);
|
||||
@ -88,7 +95,7 @@ export class MaterialBase
|
||||
if (this.type !== rhs.type) {
|
||||
return false;
|
||||
}
|
||||
if (this.isDefault !== rhs.isDefault) {
|
||||
if (this.source !== rhs.source) {
|
||||
return false;
|
||||
}
|
||||
if (this.name !== rhs.name) {
|
||||
|
||||
@ -9,6 +9,7 @@ export class Mesh extends ModelObject3D
|
||||
this.vertexColors = [];
|
||||
this.normals = [];
|
||||
this.uvs = [];
|
||||
this.lines = [];
|
||||
this.triangles = [];
|
||||
}
|
||||
|
||||
@ -32,6 +33,20 @@ export class Mesh extends ModelObject3D
|
||||
return this.uvs.length;
|
||||
}
|
||||
|
||||
LineCount ()
|
||||
{
|
||||
return this.lines.length;
|
||||
}
|
||||
|
||||
LineSegmentCount ()
|
||||
{
|
||||
let lineSegmentCount = 0;
|
||||
for (let line of this.lines) {
|
||||
lineSegmentCount += line.SegmentCount ();
|
||||
}
|
||||
return lineSegmentCount;
|
||||
}
|
||||
|
||||
TriangleCount ()
|
||||
{
|
||||
return this.triangles.length;
|
||||
@ -101,6 +116,17 @@ SetNormal (index, normal)
|
||||
return this.uvs[index];
|
||||
}
|
||||
|
||||
AddLine (line)
|
||||
{
|
||||
this.lines.push (line);
|
||||
return this.lines.length - 1;
|
||||
}
|
||||
|
||||
GetLine (index)
|
||||
{
|
||||
return this.lines[index];
|
||||
}
|
||||
|
||||
AddTriangle (triangle)
|
||||
{
|
||||
this.triangles.push (triangle);
|
||||
@ -163,6 +189,11 @@ SetNormal (index, normal)
|
||||
cloned.AddTextureUV (uv.Clone ());
|
||||
}
|
||||
|
||||
for (let i = 0; i < this.LineCount (); i++) {
|
||||
let line = this.GetLine (i);
|
||||
cloned.AddLine (line.Clone ());
|
||||
}
|
||||
|
||||
for (let i = 0; i < this.TriangleCount (); i++) {
|
||||
let triangle = this.GetTriangle (i);
|
||||
cloned.AddTriangle (triangle.Clone ());
|
||||
|
||||
@ -65,6 +65,16 @@ export class MeshInstance extends ModelObject3D
|
||||
return this.mesh.TextureUVCount ();
|
||||
}
|
||||
|
||||
LineCount ()
|
||||
{
|
||||
return this.mesh.LineCount ();
|
||||
}
|
||||
|
||||
LineSegmentCount ()
|
||||
{
|
||||
return this.mesh.LineSegmentCount ();
|
||||
}
|
||||
|
||||
TriangleCount ()
|
||||
{
|
||||
return this.mesh.TriangleCount ();
|
||||
|
||||
@ -1,18 +1,9 @@
|
||||
import { CrossVector3D, SubCoord3D } from '../geometry/coord3d.js';
|
||||
import { Transformation } from '../geometry/transformation.js';
|
||||
|
||||
export const MeshType =
|
||||
export function IsEmptyMesh (mesh)
|
||||
{
|
||||
Empty : 0,
|
||||
TriangleMesh : 1
|
||||
};
|
||||
|
||||
export function GetMeshType (mesh)
|
||||
{
|
||||
if (mesh.TriangleCount () > 0) {
|
||||
return MeshType.TriangleMesh;
|
||||
}
|
||||
return MeshType.Empty;
|
||||
return mesh.LineCount () === 0 && mesh.TriangleCount () === 0;
|
||||
}
|
||||
|
||||
export function CalculateTriangleNormal (v0, v1, v2)
|
||||
|
||||
@ -93,6 +93,24 @@ export class Model extends ModelObject3D
|
||||
return count;
|
||||
}
|
||||
|
||||
LineCount ()
|
||||
{
|
||||
let count = 0;
|
||||
this.EnumerateMeshInstances ((meshInstance) => {
|
||||
count += meshInstance.LineCount ();
|
||||
});
|
||||
return count;
|
||||
}
|
||||
|
||||
LineSegmentCount ()
|
||||
{
|
||||
let count = 0;
|
||||
this.EnumerateMeshInstances ((meshInstance) => {
|
||||
count += meshInstance.LineSegmentCount ();
|
||||
});
|
||||
return count;
|
||||
}
|
||||
|
||||
TriangleCount ()
|
||||
{
|
||||
let count = 0;
|
||||
|
||||
@ -1,19 +1,20 @@
|
||||
import { CopyObjectAttributes } from '../core/core.js';
|
||||
import { AddCoord3D, Coord3D, CoordIsEqual3D } from '../geometry/coord3d.js';
|
||||
import { RGBColor } from './color.js';
|
||||
import { PhongMaterial } from './material.js';
|
||||
import { CalculateTriangleNormal, GetMeshType, MeshType } from './meshutils.js';
|
||||
import { MaterialSource, PhongMaterial } from './material.js';
|
||||
import { CalculateTriangleNormal, IsEmptyMesh } from './meshutils.js';
|
||||
|
||||
class ModelFinalizer
|
||||
{
|
||||
constructor (params)
|
||||
{
|
||||
this.params = {
|
||||
getDefaultMaterialColor : () => {
|
||||
return new RGBColor (0, 0, 0);
|
||||
}
|
||||
defaultLineMaterialColor : new RGBColor (0, 0, 0),
|
||||
defaultMaterialColor : new RGBColor (0, 0, 0)
|
||||
};
|
||||
CopyObjectAttributes (params, this.params);
|
||||
|
||||
this.defaultLineMaterialIndex = null;
|
||||
this.defaultMaterialIndex = null;
|
||||
}
|
||||
|
||||
@ -56,8 +57,7 @@ class ModelFinalizer
|
||||
{
|
||||
for (let meshIndex = 0; meshIndex < model.MeshCount (); meshIndex++) {
|
||||
let mesh = model.GetMesh (meshIndex);
|
||||
let type = GetMeshType (mesh);
|
||||
if (type === MeshType.Empty) {
|
||||
if (IsEmptyMesh (mesh)) {
|
||||
model.RemoveMesh (meshIndex);
|
||||
meshIndex = meshIndex - 1;
|
||||
continue;
|
||||
@ -139,12 +139,18 @@ class ModelFinalizer
|
||||
calculateCurveNormals : false
|
||||
};
|
||||
|
||||
for (let i = 0; i < mesh.LineCount (); i++) {
|
||||
let line = mesh.GetLine (i);
|
||||
if (line.mat === null) {
|
||||
line.mat = this.GetDefaultMaterialIndex (model, MaterialSource.DefaultLine);
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < mesh.TriangleCount (); i++) {
|
||||
let triangle = mesh.GetTriangle (i);
|
||||
this.FinalizeTriangle (mesh, triangle, meshStatus);
|
||||
|
||||
if (triangle.mat === null) {
|
||||
triangle.mat = this.GetDefaultMaterialIndex (model);
|
||||
triangle.mat = this.GetDefaultMaterialIndex (model, MaterialSource.DefaultFace);
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,20 +203,33 @@ class ModelFinalizer
|
||||
}
|
||||
}
|
||||
|
||||
GetDefaultMaterialIndex (model)
|
||||
GetDefaultMaterialIndex (model, source)
|
||||
{
|
||||
if (this.defaultMaterialIndex === null) {
|
||||
let defaultMaterialColor = this.params.getDefaultMaterialColor ();
|
||||
function GetIndex (model, index, source, color)
|
||||
{
|
||||
if (index !== null) {
|
||||
return index;
|
||||
}
|
||||
let defaultMaterial = new PhongMaterial ();
|
||||
defaultMaterial.color = defaultMaterialColor;
|
||||
defaultMaterial.isDefault = true;
|
||||
this.defaultMaterialIndex = model.AddMaterial (defaultMaterial);
|
||||
defaultMaterial.color = color;
|
||||
defaultMaterial.source = source;
|
||||
return model.AddMaterial (defaultMaterial);
|
||||
}
|
||||
|
||||
if (source === MaterialSource.DefaultLine) {
|
||||
this.defaultLineMaterialIndex = GetIndex (model, this.defaultLineMaterialIndex, MaterialSource.DefaultLine, this.params.defaultLineMaterialColor);
|
||||
return this.defaultLineMaterialIndex;
|
||||
} else if (source === MaterialSource.DefaultFace) {
|
||||
this.defaultMaterialIndex = GetIndex (model, this.defaultMaterialIndex, MaterialSource.DefaultFace, this.params.defaultMaterialColor);
|
||||
return this.defaultMaterialIndex;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return this.defaultMaterialIndex;
|
||||
}
|
||||
|
||||
Reset ()
|
||||
{
|
||||
this.defaultLineMaterialIndex = null;
|
||||
this.defaultMaterialIndex = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { BoundingBoxCalculator3D } from '../geometry/box3d.js';
|
||||
import { Octree } from '../geometry/octree.js';
|
||||
import { GetMeshType, MeshType } from './meshutils.js';
|
||||
import { MaterialSource } from './material.js';
|
||||
import { IsEmptyMesh } from './meshutils.js';
|
||||
import { Model } from './model.js';
|
||||
import { Topology } from './topology.js';
|
||||
|
||||
@ -8,7 +9,7 @@ export function IsModelEmpty (model)
|
||||
{
|
||||
let isEmpty = true;
|
||||
model.EnumerateMeshInstances ((meshInstance) => {
|
||||
if (GetMeshType (meshInstance) !== MeshType.Empty) {
|
||||
if (!IsEmptyMesh (meshInstance)) {
|
||||
isEmpty = false;
|
||||
}
|
||||
});
|
||||
@ -95,23 +96,26 @@ export function IsTwoManifold (object3D)
|
||||
}
|
||||
}
|
||||
|
||||
export function HasDefaultMaterial (model)
|
||||
export function GetDefaultMaterials (model)
|
||||
{
|
||||
let defaultMaterials = [];
|
||||
for (let i = 0; i < model.MaterialCount (); i++) {
|
||||
let material = model.GetMaterial (i);
|
||||
if (material.isDefault && !material.vertexColors) {
|
||||
return true;
|
||||
if (material.source !== MaterialSource.Model && !material.vertexColors) {
|
||||
defaultMaterials.push (material);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return defaultMaterials;
|
||||
}
|
||||
|
||||
export function ReplaceDefaultMaterialColor (model, color)
|
||||
export function ReplaceDefaultMaterialsColor (model, color, lineColor)
|
||||
{
|
||||
for (let i = 0; i < model.MaterialCount (); i++) {
|
||||
let material = model.GetMaterial (i);
|
||||
if (material.isDefault) {
|
||||
if (material.source === MaterialSource.DefaultFace) {
|
||||
material.color = color;
|
||||
} else if (material.source === MaterialSource.DefaultLine) {
|
||||
material.color = lineColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,16 @@ export class Object3D
|
||||
return 0;
|
||||
}
|
||||
|
||||
LineCount ()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
LineSegmentCount ()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
TriangleCount ()
|
||||
{
|
||||
return 0;
|
||||
|
||||
@ -269,6 +269,12 @@ export class ParameterListBuilder
|
||||
return this;
|
||||
}
|
||||
|
||||
AddDefaultLineColor (color)
|
||||
{
|
||||
this.AddUrlPart ('defaultlinecolor', ParameterConverter.RGBColorToString (color));
|
||||
return this;
|
||||
}
|
||||
|
||||
AddEdgeSettings (edgeSettings)
|
||||
{
|
||||
this.AddUrlPart ('edgesettings', ParameterConverter.EdgeSettingsToString (edgeSettings));
|
||||
@ -344,6 +350,12 @@ export class ParameterListParser
|
||||
return ParameterConverter.StringToRGBColor (colorParams);
|
||||
}
|
||||
|
||||
GetDefaultLineColor ()
|
||||
{
|
||||
let colorParams = this.GetKeywordParams ('defaultlinecolor');
|
||||
return ParameterConverter.StringToRGBColor (colorParams);
|
||||
}
|
||||
|
||||
GetEdgeSettings ()
|
||||
{
|
||||
let edgeSettingsParams = this.GetKeywordParams ('edgesettings');
|
||||
|
||||
@ -1,13 +1,19 @@
|
||||
import { RunTasksBatch } from '../core/taskrunner.js';
|
||||
import { IsEqual } from '../geometry/geometry.js';
|
||||
import { CreateObjectUrl, CreateObjectUrlWithMimeType } from '../io/bufferutils.js';
|
||||
import { MaterialType } from '../model/material.js';
|
||||
import { MaterialSource, MaterialType } from '../model/material.js';
|
||||
import { MeshInstance, MeshInstanceId } from '../model/meshinstance.js';
|
||||
import { GetMeshType, MeshType } from '../model/meshutils.js';
|
||||
import { IsEmptyMesh } from '../model/meshutils.js';
|
||||
import { ConvertColorToThreeColor, GetShadingType, ShadingType } from './threeutils.js';
|
||||
|
||||
import * as THREE from 'three';
|
||||
|
||||
export const MaterialGeometryType =
|
||||
{
|
||||
Line : 1,
|
||||
Face : 2
|
||||
};
|
||||
|
||||
export class ModelToThreeConversionParams
|
||||
{
|
||||
constructor ()
|
||||
@ -20,7 +26,7 @@ export class ModelToThreeConversionOutput
|
||||
{
|
||||
constructor ()
|
||||
{
|
||||
this.defaultMaterial = null;
|
||||
this.defaultMaterials = [];
|
||||
this.objectUrls = [];
|
||||
}
|
||||
}
|
||||
@ -97,50 +103,42 @@ export class ThreeNodeTree
|
||||
}
|
||||
}
|
||||
|
||||
export function ConvertModelToThreeObject (model, params, output, callbacks)
|
||||
export class ThreeMaterialHandler
|
||||
{
|
||||
function CreateThreeMaterial (stateHandler, model, materialIndex, shadingType, params, output)
|
||||
constructor (model, stateHandler, conversionParams, conversionOutput)
|
||||
{
|
||||
function SetTextureParameters (texture, threeTexture)
|
||||
{
|
||||
threeTexture.wrapS = THREE.RepeatWrapping;
|
||||
threeTexture.wrapT = THREE.RepeatWrapping;
|
||||
threeTexture.rotation = texture.rotation;
|
||||
threeTexture.offset.x = texture.offset.x;
|
||||
threeTexture.offset.y = texture.offset.y;
|
||||
threeTexture.repeat.x = texture.scale.x;
|
||||
threeTexture.repeat.y = texture.scale.y;
|
||||
}
|
||||
this.model = model;
|
||||
this.stateHandler = stateHandler;
|
||||
this.conversionParams = conversionParams;
|
||||
this.conversionOutput = conversionOutput;
|
||||
|
||||
function LoadTexture (stateHandler, threeMaterial, texture, output, onTextureLoaded)
|
||||
{
|
||||
if (texture === null || !texture.IsValid ()) {
|
||||
return;
|
||||
}
|
||||
let loader = new THREE.TextureLoader ();
|
||||
stateHandler.OnTextureNeeded ();
|
||||
let textureObjectUrl = null;
|
||||
if (texture.mimeType !== null) {
|
||||
textureObjectUrl = CreateObjectUrlWithMimeType (texture.buffer, texture.mimeType);
|
||||
} else {
|
||||
textureObjectUrl = CreateObjectUrl (texture.buffer);
|
||||
}
|
||||
output.objectUrls.push (textureObjectUrl);
|
||||
loader.load (textureObjectUrl,
|
||||
(threeTexture) => {
|
||||
SetTextureParameters (texture, threeTexture);
|
||||
threeMaterial.needsUpdate = true;
|
||||
onTextureLoaded (threeTexture);
|
||||
stateHandler.OnTextureLoaded ();
|
||||
},
|
||||
null,
|
||||
(err) => {
|
||||
stateHandler.OnTextureLoaded ();
|
||||
}
|
||||
);
|
||||
}
|
||||
this.shadingType = GetShadingType (model);
|
||||
this.modelToThreeLineMaterial = new Map ();
|
||||
this.modelToThreeMaterial = new Map ();
|
||||
}
|
||||
|
||||
let material = model.GetMaterial (materialIndex);
|
||||
GetThreeMaterial (modelMaterialIndex, geometryType)
|
||||
{
|
||||
if (geometryType === MaterialGeometryType.Face) {
|
||||
if (!this.modelToThreeMaterial.has (modelMaterialIndex)) {
|
||||
let threeMaterial = this.CreateThreeFaceMaterial (modelMaterialIndex);
|
||||
this.modelToThreeMaterial.set (modelMaterialIndex, threeMaterial);
|
||||
}
|
||||
return this.modelToThreeMaterial.get (modelMaterialIndex);
|
||||
} else if (geometryType === MaterialGeometryType.Line) {
|
||||
if (!this.modelToThreeLineMaterial.has (modelMaterialIndex)) {
|
||||
let threeMaterial = this.CreateThreeLineMaterial (modelMaterialIndex);
|
||||
this.modelToThreeLineMaterial.set (modelMaterialIndex, threeMaterial);
|
||||
}
|
||||
return this.modelToThreeLineMaterial.get (modelMaterialIndex);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
CreateThreeFaceMaterial (materialIndex)
|
||||
{
|
||||
let material = this.model.GetMaterial (materialIndex);
|
||||
let baseColor = ConvertColorToThreeColor (material.color);
|
||||
if (material.vertexColors) {
|
||||
baseColor.setRGB (1.0, 1.0, 1.0);
|
||||
@ -155,12 +153,12 @@ export function ConvertModelToThreeObject (model, params, output, callbacks)
|
||||
side : THREE.DoubleSide
|
||||
};
|
||||
|
||||
if (params.forceMediumpForMaterials) {
|
||||
if (this.conversionParams.forceMediumpForMaterials) {
|
||||
materialParams.precision = 'mediump';
|
||||
}
|
||||
|
||||
let threeMaterial = null;
|
||||
if (shadingType === ShadingType.Phong) {
|
||||
if (this.shadingType === ShadingType.Phong) {
|
||||
threeMaterial = new THREE.MeshPhongMaterial (materialParams);
|
||||
if (material.type === MaterialType.Phong) {
|
||||
let specularColor = ConvertColorToThreeColor (material.specular);
|
||||
@ -169,16 +167,16 @@ export function ConvertModelToThreeObject (model, params, output, callbacks)
|
||||
}
|
||||
threeMaterial.specular = specularColor;
|
||||
threeMaterial.shininess = material.shininess * 100.0;
|
||||
LoadTexture (stateHandler, threeMaterial, material.specularMap, output, (threeTexture) => {
|
||||
this.LoadFaceTexture (threeMaterial, material.specularMap, (threeTexture) => {
|
||||
threeMaterial.specularMap = threeTexture;
|
||||
});
|
||||
}
|
||||
} else if (shadingType === ShadingType.Physical) {
|
||||
} else if (this.shadingType === ShadingType.Physical) {
|
||||
threeMaterial = new THREE.MeshStandardMaterial (materialParams);
|
||||
if (material.type === MaterialType.Physical) {
|
||||
threeMaterial.metalness = material.metalness;
|
||||
threeMaterial.roughness = material.roughness;
|
||||
LoadTexture (stateHandler, threeMaterial, material.metalnessMap, output, (threeTexture) => {
|
||||
this.LoadFaceTexture (threeMaterial, material.metalnessMap, (threeTexture) => {
|
||||
threeMaterial.metalness = 1.0;
|
||||
threeMaterial.roughness = 1.0;
|
||||
threeMaterial.metalnessMap = threeTexture;
|
||||
@ -190,33 +188,151 @@ export function ConvertModelToThreeObject (model, params, output, callbacks)
|
||||
let emissiveColor = ConvertColorToThreeColor (material.emissive);
|
||||
threeMaterial.emissive = emissiveColor;
|
||||
|
||||
LoadTexture (stateHandler, threeMaterial, material.diffuseMap, output, (threeTexture) => {
|
||||
this.LoadFaceTexture (threeMaterial, material.diffuseMap, (threeTexture) => {
|
||||
if (!material.multiplyDiffuseMap) {
|
||||
threeMaterial.color.setRGB (1.0, 1.0, 1.0);
|
||||
}
|
||||
threeMaterial.map = threeTexture;
|
||||
});
|
||||
LoadTexture (stateHandler, threeMaterial, material.bumpMap, output, (threeTexture) => {
|
||||
this.LoadFaceTexture (threeMaterial, material.bumpMap, (threeTexture) => {
|
||||
threeMaterial.bumpMap = threeTexture;
|
||||
});
|
||||
LoadTexture (stateHandler, threeMaterial, material.normalMap, output, (threeTexture) => {
|
||||
this.LoadFaceTexture (threeMaterial, material.normalMap, (threeTexture) => {
|
||||
threeMaterial.normalMap = threeTexture;
|
||||
});
|
||||
LoadTexture (stateHandler, threeMaterial, material.emissiveMap, output, (threeTexture) => {
|
||||
this.LoadFaceTexture (threeMaterial, material.emissiveMap, (threeTexture) => {
|
||||
threeMaterial.emissiveMap = threeTexture;
|
||||
});
|
||||
|
||||
if (material.isDefault) {
|
||||
output.defaultMaterial = threeMaterial;
|
||||
if (material.source !== MaterialSource.Model) {
|
||||
threeMaterial.userData.source = material.source;
|
||||
this.conversionOutput.defaultMaterials.push (threeMaterial);
|
||||
}
|
||||
|
||||
return threeMaterial;
|
||||
}
|
||||
|
||||
function CreateThreeMesh (meshInstance, modelThreeMaterials)
|
||||
CreateThreeLineMaterial (materialIndex)
|
||||
{
|
||||
let material = this.model.GetMaterial (materialIndex);
|
||||
let baseColor = ConvertColorToThreeColor (material.color);
|
||||
let materialParams = {
|
||||
color : baseColor,
|
||||
opacity : material.opacity
|
||||
};
|
||||
|
||||
if (this.conversionParams.forceMediumpForMaterials) {
|
||||
materialParams.precision = 'mediump';
|
||||
}
|
||||
|
||||
let threeMaterial = new THREE.LineBasicMaterial (materialParams);
|
||||
if (material.source !== MaterialSource.Model) {
|
||||
threeMaterial.userData.source = material.source;
|
||||
this.conversionOutput.defaultMaterials.push (threeMaterial);
|
||||
}
|
||||
|
||||
return threeMaterial;
|
||||
}
|
||||
|
||||
LoadFaceTexture (threeMaterial, texture, onTextureLoaded)
|
||||
{
|
||||
function SetTextureParameters (texture, threeTexture)
|
||||
{
|
||||
threeTexture.wrapS = THREE.RepeatWrapping;
|
||||
threeTexture.wrapT = THREE.RepeatWrapping;
|
||||
threeTexture.rotation = texture.rotation;
|
||||
threeTexture.offset.x = texture.offset.x;
|
||||
threeTexture.offset.y = texture.offset.y;
|
||||
threeTexture.repeat.x = texture.scale.x;
|
||||
threeTexture.repeat.y = texture.scale.y;
|
||||
}
|
||||
|
||||
if (texture === null || !texture.IsValid ()) {
|
||||
return;
|
||||
}
|
||||
let loader = new THREE.TextureLoader ();
|
||||
this.stateHandler.OnTextureNeeded ();
|
||||
let textureObjectUrl = null;
|
||||
if (texture.mimeType !== null) {
|
||||
textureObjectUrl = CreateObjectUrlWithMimeType (texture.buffer, texture.mimeType);
|
||||
} else {
|
||||
textureObjectUrl = CreateObjectUrl (texture.buffer);
|
||||
}
|
||||
this.conversionOutput.objectUrls.push (textureObjectUrl);
|
||||
loader.load (textureObjectUrl,
|
||||
(threeTexture) => {
|
||||
SetTextureParameters (texture, threeTexture);
|
||||
threeMaterial.needsUpdate = true;
|
||||
onTextureLoaded (threeTexture);
|
||||
this.stateHandler.OnTextureLoaded ();
|
||||
},
|
||||
null,
|
||||
(err) => {
|
||||
this.stateHandler.OnTextureLoaded ();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class ThreeMeshMaterialHandler
|
||||
{
|
||||
constructor (threeGeometry, geometryType, materialHandler)
|
||||
{
|
||||
this.threeGeometry = threeGeometry;
|
||||
this.geometryType = geometryType;
|
||||
this.materialHandler = materialHandler;
|
||||
|
||||
this.itemVertexCount = null;
|
||||
if (geometryType === MaterialGeometryType.Face) {
|
||||
this.itemVertexCount = 3;
|
||||
} else if (geometryType === MaterialGeometryType.Line) {
|
||||
this.itemVertexCount = 2;
|
||||
}
|
||||
|
||||
this.meshThreeMaterials = [];
|
||||
this.meshOriginalMaterials = [];
|
||||
|
||||
this.groupStart = null;
|
||||
this.previousMaterialIndex = null;
|
||||
}
|
||||
|
||||
ProcessItem (itemIndex, materialIndex)
|
||||
{
|
||||
if (this.previousMaterialIndex !== materialIndex) {
|
||||
if (this.groupStart !== null) {
|
||||
this.AddGroup (this.groupStart, itemIndex - 1);
|
||||
}
|
||||
this.groupStart = itemIndex;
|
||||
|
||||
let threeMaterial = this.materialHandler.GetThreeMaterial (materialIndex, this.geometryType);
|
||||
this.meshThreeMaterials.push (threeMaterial);
|
||||
this.meshOriginalMaterials.push (materialIndex);
|
||||
|
||||
this.previousMaterialIndex = materialIndex;
|
||||
}
|
||||
}
|
||||
|
||||
Finalize (itemCount)
|
||||
{
|
||||
this.AddGroup (this.groupStart, itemCount - 1);
|
||||
}
|
||||
|
||||
AddGroup (start, end)
|
||||
{
|
||||
let materialIndex = this.meshThreeMaterials.length - 1;
|
||||
this.threeGeometry.addGroup (start * this.itemVertexCount, (end - start + 1) * this.itemVertexCount, materialIndex);
|
||||
}
|
||||
}
|
||||
|
||||
export function ConvertModelToThreeObject (model, conversionParams, conversionOutput, callbacks)
|
||||
{
|
||||
function CreateThreeTriangleMesh (meshInstance, materialHandler)
|
||||
{
|
||||
let mesh = meshInstance.mesh;
|
||||
let triangleCount = mesh.TriangleCount ();
|
||||
if (triangleCount === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let triangleIndices = [];
|
||||
for (let i = 0; i < triangleCount; i++) {
|
||||
@ -229,25 +345,17 @@ export function ConvertModelToThreeObject (model, params, output, callbacks)
|
||||
});
|
||||
|
||||
let threeGeometry = new THREE.BufferGeometry ();
|
||||
let meshThreeMaterials = [];
|
||||
let meshOriginalMaterials = [];
|
||||
let modelToThreeMaterials = new Map ();
|
||||
let meshMaterialHandler = new ThreeMeshMaterialHandler (threeGeometry, MaterialGeometryType.Face, materialHandler);
|
||||
|
||||
let vertices = [];
|
||||
let vertexColors = [];
|
||||
let normals = [];
|
||||
let uvs = [];
|
||||
|
||||
let groups = [];
|
||||
groups.push ({
|
||||
start : 0,
|
||||
end : -1
|
||||
});
|
||||
|
||||
let meshHasVertexColors = (mesh.VertexColorCount () > 0);
|
||||
let meshHasUVs = (mesh.TextureUVCount () > 0);
|
||||
for (let i = 0; i < triangleIndices.length; i++) {
|
||||
let triangleIndex = triangleIndices[i];
|
||||
let processedTriangleCount = 0;
|
||||
for (let triangleIndex of triangleIndices) {
|
||||
let triangle = mesh.GetTriangle (triangleIndex);
|
||||
|
||||
let v0 = mesh.GetVertex (triangle.v0);
|
||||
@ -286,22 +394,10 @@ export function ConvertModelToThreeObject (model, params, output, callbacks)
|
||||
uvs.push (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
let modelMaterialIndex = triangle.mat;
|
||||
if (!modelToThreeMaterials.has (modelMaterialIndex)) {
|
||||
modelToThreeMaterials.set (modelMaterialIndex, meshThreeMaterials.length);
|
||||
meshThreeMaterials.push (modelThreeMaterials[modelMaterialIndex]);
|
||||
meshOriginalMaterials.push (modelMaterialIndex);
|
||||
if (i > 0) {
|
||||
groups[groups.length - 1].end = i - 1;
|
||||
groups.push ({
|
||||
start : groups[groups.length - 1].end + 1,
|
||||
end : -1
|
||||
});
|
||||
}
|
||||
}
|
||||
meshMaterialHandler.ProcessItem (processedTriangleCount, triangle.mat);
|
||||
processedTriangleCount += 1;
|
||||
}
|
||||
|
||||
groups[groups.length - 1].end = triangleCount - 1;
|
||||
meshMaterialHandler.Finalize (processedTriangleCount);
|
||||
|
||||
threeGeometry.setAttribute ('position', new THREE.Float32BufferAttribute (vertices, 3));
|
||||
if (vertexColors.length !== 0) {
|
||||
@ -311,32 +407,86 @@ export function ConvertModelToThreeObject (model, params, output, callbacks)
|
||||
if (uvs.length !== 0) {
|
||||
threeGeometry.setAttribute ('uv', new THREE.Float32BufferAttribute (uvs, 2));
|
||||
}
|
||||
for (let i = 0; i < groups.length; i++) {
|
||||
let group = groups[i];
|
||||
threeGeometry.addGroup (group.start * 3, (group.end - group.start + 1) * 3, i);
|
||||
}
|
||||
|
||||
let threeMesh = new THREE.Mesh (threeGeometry, meshThreeMaterials);
|
||||
let threeMesh = new THREE.Mesh (threeGeometry, meshMaterialHandler.meshThreeMaterials);
|
||||
threeMesh.name = mesh.GetName ();
|
||||
threeMesh.userData = {
|
||||
originalMeshInstance : meshInstance,
|
||||
originalMaterials : meshOriginalMaterials,
|
||||
originalMaterials : meshMaterialHandler.meshOriginalMaterials,
|
||||
threeMaterials : null
|
||||
};
|
||||
|
||||
return threeMesh;
|
||||
}
|
||||
|
||||
function ConvertMesh (threeObject, meshInstance, modelThreeMaterials)
|
||||
function CreateThreeLineMesh (meshInstance, materialHandler)
|
||||
{
|
||||
let type = GetMeshType (meshInstance.mesh);
|
||||
if (type === MeshType.TriangleMesh) {
|
||||
let threeMesh = CreateThreeMesh (meshInstance, modelThreeMaterials);
|
||||
threeObject.add (threeMesh);
|
||||
let mesh = meshInstance.mesh;
|
||||
let lineCount = mesh.LineCount ();
|
||||
if (lineCount === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let lineIndices = [];
|
||||
for (let i = 0; i < lineCount; i++) {
|
||||
lineIndices.push (i);
|
||||
}
|
||||
lineIndices.sort ((a, b) => {
|
||||
let aLine = mesh.GetLine (a);
|
||||
let bLine = mesh.GetLine (b);
|
||||
return aLine.mat - bLine.mat;
|
||||
});
|
||||
|
||||
let threeGeometry = new THREE.BufferGeometry ();
|
||||
let meshMaterialHandler = new ThreeMeshMaterialHandler (threeGeometry, MaterialGeometryType.Line, materialHandler);
|
||||
|
||||
let vertices = [];
|
||||
let segmentCount = 0;
|
||||
for (let i = 0; i < lineIndices.length; i++) {
|
||||
let line = mesh.GetLine (lineIndices[i]);
|
||||
let lineVertices = line.GetVertices ();
|
||||
for (let i = 0; i < lineVertices.length; i++) {
|
||||
let vertexIndex = lineVertices[i];
|
||||
let vertex = mesh.GetVertex (vertexIndex);
|
||||
vertices.push (vertex.x, vertex.y, vertex.z);
|
||||
if (i > 0 && i < lineVertices.length - 1) {
|
||||
vertices.push (vertex.x, vertex.y, vertex.z);
|
||||
}
|
||||
}
|
||||
meshMaterialHandler.ProcessItem (segmentCount, line.mat);
|
||||
segmentCount += line.SegmentCount ();
|
||||
}
|
||||
meshMaterialHandler.Finalize (segmentCount);
|
||||
|
||||
threeGeometry.setAttribute ('position', new THREE.Float32BufferAttribute (vertices, 3));
|
||||
|
||||
let threeLine = new THREE.LineSegments (threeGeometry, meshMaterialHandler.meshThreeMaterials);
|
||||
threeLine.userData = {
|
||||
originalMeshInstance : meshInstance,
|
||||
originalMaterials : meshMaterialHandler.meshOriginalMaterials,
|
||||
threeMaterials : null
|
||||
};
|
||||
return threeLine;
|
||||
}
|
||||
|
||||
function ConvertMesh (threeObject, meshInstance, materialHandler)
|
||||
{
|
||||
if (IsEmptyMesh (meshInstance.mesh)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let triangleMesh = CreateThreeTriangleMesh (meshInstance, materialHandler);
|
||||
if (triangleMesh !== null) {
|
||||
threeObject.add (triangleMesh);
|
||||
}
|
||||
|
||||
let lineMesh = CreateThreeLineMesh (meshInstance, materialHandler);
|
||||
if (lineMesh !== null) {
|
||||
threeObject.add (lineMesh);
|
||||
}
|
||||
}
|
||||
|
||||
function ConvertNodeHierarchy (threeRootNode, model, modelThreeMaterials, stateHandler)
|
||||
function ConvertNodeHierarchy (threeRootNode, model, materialHandler, stateHandler)
|
||||
{
|
||||
let nodeTree = new ThreeNodeTree (model, threeRootNode);
|
||||
let threeNodeItems = nodeTree.GetNodeItems ();
|
||||
@ -345,7 +495,7 @@ export function ConvertModelToThreeObject (model, params, output, callbacks)
|
||||
runTask : (firstMeshInstanceIndex, lastMeshInstanceIndex, onReady) => {
|
||||
for (let meshInstanceIndex = firstMeshInstanceIndex; meshInstanceIndex <= lastMeshInstanceIndex; meshInstanceIndex++) {
|
||||
let nodeItem = threeNodeItems[meshInstanceIndex];
|
||||
ConvertMesh (nodeItem.threeNode, nodeItem.meshInstance, modelThreeMaterials);
|
||||
ConvertMesh (nodeItem.threeNode, nodeItem.meshInstance, materialHandler);
|
||||
}
|
||||
onReady ();
|
||||
},
|
||||
@ -356,14 +506,7 @@ export function ConvertModelToThreeObject (model, params, output, callbacks)
|
||||
}
|
||||
|
||||
let stateHandler = new ThreeConversionStateHandler (callbacks);
|
||||
let shadingType = GetShadingType (model);
|
||||
|
||||
let modelThreeMaterials = [];
|
||||
for (let materialIndex = 0; materialIndex < model.MaterialCount (); materialIndex++) {
|
||||
let threeMaterial = CreateThreeMaterial (stateHandler, model, materialIndex, shadingType, params, output);
|
||||
modelThreeMaterials.push (threeMaterial);
|
||||
}
|
||||
|
||||
let materialHandler = new ThreeMaterialHandler (model, stateHandler, conversionParams, conversionOutput);
|
||||
let threeObject = new THREE.Object3D ();
|
||||
ConvertNodeHierarchy (threeObject, model, modelThreeMaterials, stateHandler);
|
||||
ConvertNodeHierarchy (threeObject, model, materialHandler, stateHandler);
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { Direction } from '../geometry/geometry.js';
|
||||
import { Importer } from '../import/importer.js';
|
||||
import { RevokeObjectUrl } from '../io/bufferutils.js';
|
||||
import { MaterialSource } from '../model/material.js';
|
||||
import { ConvertModelToThreeObject, ModelToThreeConversionOutput, ModelToThreeConversionParams } from './threeconverter.js';
|
||||
import { ConvertColorToThreeColor, HasHighpDriverIssue } from './threeutils.js';
|
||||
|
||||
@ -12,7 +13,7 @@ export class ThreeModelLoader
|
||||
{
|
||||
this.importer = new Importer ();
|
||||
this.inProgress = false;
|
||||
this.defaultMaterial = null;
|
||||
this.defaultMaterials = null;
|
||||
this.objectUrls = null;
|
||||
this.hasHighpDriverIssue = HasHighpDriverIssue ();
|
||||
}
|
||||
@ -60,7 +61,7 @@ export class ThreeModelLoader
|
||||
callbacks.onTextureLoaded ();
|
||||
},
|
||||
onModelLoaded : (threeObject) => {
|
||||
this.defaultMaterial = output.defaultMaterial;
|
||||
this.defaultMaterials = output.defaultMaterials;
|
||||
this.objectUrls = output.objectUrls;
|
||||
if (importResult.upVector === Direction.X) {
|
||||
let rotation = new THREE.Quaternion ().setFromAxisAngle (new THREE.Vector3 (0.0, 0.0, 1.0), Math.PI / 2.0);
|
||||
@ -86,15 +87,23 @@ export class ThreeModelLoader
|
||||
return this.importer;
|
||||
}
|
||||
|
||||
GetDefaultMaterial ()
|
||||
GetDefaultMaterials ()
|
||||
{
|
||||
return this.defaultMaterial;
|
||||
return this.defaultMaterials;
|
||||
}
|
||||
|
||||
ReplaceDefaultMaterialColor (defaultColor)
|
||||
ReplaceDefaultMaterialsColor (defaultColor, defaultLineColor)
|
||||
{
|
||||
if (this.defaultMaterial !== null && !this.defaultMaterial.vertexColors) {
|
||||
this.defaultMaterial.color = ConvertColorToThreeColor (defaultColor);
|
||||
if (this.defaultMaterials !== null) {
|
||||
for (let defaultMaterial of this.defaultMaterials) {
|
||||
if (!defaultMaterial.vertexColors) {
|
||||
if (defaultMaterial.userData.source === MaterialSource.DefaultFace) {
|
||||
defaultMaterial.color = ConvertColorToThreeColor (defaultColor);
|
||||
} else if (defaultMaterial.userData.source === MaterialSource.DefaultLine) {
|
||||
defaultMaterial.color = ConvertColorToThreeColor (defaultLineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -210,6 +210,48 @@ export function ConvertThreeGeometryToMesh (threeGeometry, materialIndex, colorC
|
||||
return mesh;
|
||||
}
|
||||
|
||||
export function CreateHighlightMaterial (originalMaterial, highlightColor, withPolygonOffset)
|
||||
{
|
||||
let material = null;
|
||||
if (originalMaterial.type === 'MeshPhongMaterial') {
|
||||
material = new THREE.MeshPhongMaterial ({
|
||||
color : ConvertColorToThreeColor (highlightColor),
|
||||
side : THREE.DoubleSide
|
||||
});
|
||||
} else if (originalMaterial.type === 'MeshStandardMaterial') {
|
||||
material = new THREE.MeshStandardMaterial ({
|
||||
color : ConvertColorToThreeColor (highlightColor),
|
||||
side : THREE.DoubleSide
|
||||
});
|
||||
} else if (originalMaterial.type === 'LineBasicMaterial') {
|
||||
material = new THREE.LineBasicMaterial ({
|
||||
color : ConvertColorToThreeColor (highlightColor)
|
||||
});
|
||||
}
|
||||
if (material !== null && withPolygonOffset) {
|
||||
material.polygonOffset = true;
|
||||
material.polygonOffsetUnit = 1;
|
||||
material.polygonOffsetFactor = 1;
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
export function CreateHighlightMaterials (originalMaterials, highlightColor, withPolygonOffset)
|
||||
{
|
||||
let typeToHighlightMaterial = new Map ();
|
||||
let highlightMaterials = [];
|
||||
for (let originalMaterial of originalMaterials) {
|
||||
if (typeToHighlightMaterial.has (originalMaterial.type)) {
|
||||
highlightMaterials.push (typeToHighlightMaterial.get (originalMaterial.type));
|
||||
continue;
|
||||
}
|
||||
let highlightMaterial = CreateHighlightMaterial (originalMaterial, highlightColor, withPolygonOffset);
|
||||
typeToHighlightMaterial.set (originalMaterial.type, highlightMaterial);
|
||||
highlightMaterials.push (highlightMaterial);
|
||||
}
|
||||
return highlightMaterials;
|
||||
}
|
||||
|
||||
export function DisposeThreeObjects (mainObject)
|
||||
{
|
||||
if (mainObject === null) {
|
||||
|
||||
@ -24,6 +24,8 @@ export class EmbeddedViewer
|
||||
* @param {RGBAColor} [parameters.backgroundColor] Background color of the canvas.
|
||||
* @param {RGBColor} [parameters.defaultColor] Default color of the model. It has effect only
|
||||
* if the imported model doesn't specify any color.
|
||||
* @param {RGBColor} [parameters.defaultLineColor] Default line color of the model. It has effect only
|
||||
* if the imported model doesn't specify any color.
|
||||
* @param {EdgeSettings} [parameters.edgeSettings] Edge settings.
|
||||
* @param {EnvironmentSettings} [parameters.environmentSettings] Environment settings.
|
||||
* @param {function} [parameters.onModelLoaded] Callback that is called when the model with all
|
||||
@ -112,6 +114,9 @@ export class EmbeddedViewer
|
||||
if (this.parameters.defaultColor) {
|
||||
settings.defaultColor = this.parameters.defaultColor;
|
||||
}
|
||||
if (this.parameters.defaultLineColor) {
|
||||
settings.defaultLineColor = this.parameters.defaultLineColor;
|
||||
}
|
||||
|
||||
this.model = null;
|
||||
let progressDiv = null;
|
||||
@ -275,6 +280,12 @@ export function Init3DViewerElements (onReady)
|
||||
defaultColor = ParameterConverter.StringToRGBColor (defaultColorParams);
|
||||
}
|
||||
|
||||
let defaultLineColor = null;
|
||||
let defaultLineColorParams = element.getAttribute ('defaultlinecolor');
|
||||
if (defaultLineColorParams) {
|
||||
defaultLineColor = ParameterConverter.StringToRGBColor (defaultLineColorParams);
|
||||
}
|
||||
|
||||
let edgeSettings = null;
|
||||
let edgeSettingsParams = element.getAttribute ('edgesettings');
|
||||
if (edgeSettingsParams) {
|
||||
@ -305,6 +316,7 @@ export function Init3DViewerElements (onReady)
|
||||
camera : camera,
|
||||
projectionMode : projectionMode,
|
||||
backgroundColor : backgroundColor,
|
||||
defaultLineColor : defaultLineColor,
|
||||
defaultColor : defaultColor,
|
||||
edgeSettings : edgeSettings,
|
||||
environmentSettings : environmentSettings
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { SubCoord3D } from '../geometry/coord3d.js';
|
||||
import { ProjectionMode } from '../viewer/camera.js';
|
||||
import { ConvertColorToThreeColor, ShadingType } from '../threejs/threeutils.js';
|
||||
import { ShadingType } from '../threejs/threeutils.js';
|
||||
|
||||
import * as THREE from 'three';
|
||||
|
||||
@ -99,26 +99,4 @@ export class ShadingModel
|
||||
const lightDir = SubCoord3D (camera.eye, camera.center);
|
||||
this.directionalLight.position.set (lightDir.x, lightDir.y, lightDir.z);
|
||||
}
|
||||
|
||||
CreateHighlightMaterial (highlightColor, withOffset)
|
||||
{
|
||||
let material = null;
|
||||
if (this.type === ShadingType.Phong) {
|
||||
material = new THREE.MeshPhongMaterial ({
|
||||
color : ConvertColorToThreeColor (highlightColor),
|
||||
side : THREE.DoubleSide
|
||||
});
|
||||
} else if (this.type === ShadingType.Physical) {
|
||||
material = new THREE.MeshStandardMaterial ({
|
||||
color : ConvertColorToThreeColor (highlightColor),
|
||||
side : THREE.DoubleSide
|
||||
});
|
||||
}
|
||||
if (material !== null && withOffset) {
|
||||
material.polygonOffset = true;
|
||||
material.polygonOffsetUnit = 1;
|
||||
material.polygonOffsetFactor = 1;
|
||||
}
|
||||
return material;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Coord3D, CoordDistance3D, SubCoord3D } from '../geometry/coord3d.js';
|
||||
import { DegRad, Direction, IsEqual } from '../geometry/geometry.js';
|
||||
import { ColorComponentToFloat } from '../model/color.js';
|
||||
import { ShadingType } from '../threejs/threeutils.js';
|
||||
import { CreateHighlightMaterials, ShadingType } from '../threejs/threeutils.js';
|
||||
import { Camera, NavigationMode, ProjectionMode } from './camera.js';
|
||||
import { GetDomElementInnerDimensions } from './domutils.js';
|
||||
import { Navigation } from './navigation.js';
|
||||
@ -448,7 +448,7 @@ export class Viewer
|
||||
|
||||
SetMeshesVisibility (isVisible)
|
||||
{
|
||||
this.mainModel.EnumerateMeshes ((mesh) => {
|
||||
this.mainModel.EnumerateMeshesAndLines ((mesh) => {
|
||||
let visible = isVisible (mesh.userData);
|
||||
if (mesh.visible !== visible) {
|
||||
mesh.visible = visible;
|
||||
@ -465,22 +465,13 @@ export class Viewer
|
||||
|
||||
SetMeshesHighlight (highlightColor, isHighlighted)
|
||||
{
|
||||
function CreateHighlightMaterials (originalMaterials, highlightMaterial)
|
||||
{
|
||||
let highlightMaterials = [];
|
||||
for (let i = 0; i < originalMaterials.length; i++) {
|
||||
highlightMaterials.push (highlightMaterial);
|
||||
}
|
||||
return highlightMaterials;
|
||||
}
|
||||
|
||||
const highlightMaterial = this.CreateHighlightMaterial (highlightColor);
|
||||
this.mainModel.EnumerateMeshes ((mesh) => {
|
||||
let withPolygonOffset = this.mainModel.HasLinesOrEdges ();
|
||||
this.mainModel.EnumerateMeshesAndLines ((mesh) => {
|
||||
let highlighted = isHighlighted (mesh.userData);
|
||||
if (highlighted) {
|
||||
if (mesh.userData.threeMaterials === null) {
|
||||
mesh.userData.threeMaterials = mesh.material;
|
||||
mesh.material = CreateHighlightMaterials (mesh.material, highlightMaterial);
|
||||
mesh.material = CreateHighlightMaterials (mesh.userData.threeMaterials, highlightColor, withPolygonOffset);
|
||||
}
|
||||
} else {
|
||||
if (mesh.userData.threeMaterials !== null) {
|
||||
@ -493,12 +484,6 @@ export class Viewer
|
||||
this.Render ();
|
||||
}
|
||||
|
||||
CreateHighlightMaterial (highlightColor)
|
||||
{
|
||||
const showEdges = this.mainModel.edgeSettings.showEdges;
|
||||
return this.shadingModel.CreateHighlightMaterial (highlightColor, showEdges);
|
||||
}
|
||||
|
||||
GetMeshUserDataUnderMouse (mouseCoords)
|
||||
{
|
||||
let intersection = this.GetMeshIntersectionUnderMouse (mouseCoords);
|
||||
@ -528,9 +513,9 @@ export class Viewer
|
||||
return this.mainModel.GetBoundingSphere (needToProcess);
|
||||
}
|
||||
|
||||
EnumerateMeshesUserData (enumerator)
|
||||
EnumerateMeshesAndLinesUserData (enumerator)
|
||||
{
|
||||
this.mainModel.EnumerateMeshes ((mesh) => {
|
||||
this.mainModel.EnumerateMeshesAndLines ((mesh) => {
|
||||
enumerator (mesh.userData);
|
||||
});
|
||||
}
|
||||
|
||||
@ -119,14 +119,26 @@ export class ViewerMainModel
|
||||
this.edgeModel = new ViewerModel (this.scene);
|
||||
|
||||
this.edgeSettings = new EdgeSettings (false, new RGBColor (0, 0, 0), 1);
|
||||
this.hasLines = false;
|
||||
this.hasPolygonOffset = false;
|
||||
this.fullBoundingBox = null;
|
||||
}
|
||||
|
||||
SetMainObject (mainObject)
|
||||
{
|
||||
this.mainModel.SetRootObject (mainObject);
|
||||
this.hasLines = false;
|
||||
this.hasPolygonOffset = false;
|
||||
this.fullBoundingBox = null;
|
||||
|
||||
this.EnumerateLines ((line) => {
|
||||
this.hasLines = true;
|
||||
});
|
||||
|
||||
if (this.edgeSettings.showEdges) {
|
||||
this.GenerateEdgeModel ();
|
||||
}
|
||||
this.UpdatePolygonOffset ();
|
||||
}
|
||||
|
||||
UpdateWorldMatrix ()
|
||||
@ -169,7 +181,6 @@ export class ViewerMainModel
|
||||
|
||||
this.UpdateWorldMatrix ();
|
||||
this.EnumerateMeshes ((mesh) => {
|
||||
SetThreeMeshPolygonOffset (mesh, true);
|
||||
let edges = new THREE.EdgesGeometry (mesh.geometry, this.edgeSettings.edgeThreshold);
|
||||
let line = new THREE.LineSegments (edges, new THREE.LineBasicMaterial ({
|
||||
color: edgeColor
|
||||
@ -179,13 +190,26 @@ export class ViewerMainModel
|
||||
line.visible = mesh.visible;
|
||||
this.edgeModel.AddObject (line);
|
||||
});
|
||||
|
||||
this.UpdatePolygonOffset ();
|
||||
}
|
||||
|
||||
GetFullBoundingBox ()
|
||||
{
|
||||
if (this.fullBoundingBox !== null) {
|
||||
return this.fullBoundingBox;
|
||||
}
|
||||
this.fullBoundingBox = this.GetBoundingBox (() => {
|
||||
return true;
|
||||
});
|
||||
return this.fullBoundingBox;
|
||||
}
|
||||
|
||||
GetBoundingBox (needToProcess)
|
||||
{
|
||||
let hasMesh = false;
|
||||
let boundingBox = new THREE.Box3 ();
|
||||
this.EnumerateMeshes ((mesh) => {
|
||||
this.EnumerateMeshesAndLines ((mesh) => {
|
||||
if (needToProcess (mesh.userData)) {
|
||||
boundingBox.union (new THREE.Box3 ().setFromObject (mesh));
|
||||
hasMesh = true;
|
||||
@ -221,9 +245,7 @@ export class ViewerMainModel
|
||||
return;
|
||||
}
|
||||
|
||||
this.EnumerateMeshes ((mesh) => {
|
||||
SetThreeMeshPolygonOffset (mesh, false);
|
||||
});
|
||||
this.UpdatePolygonOffset ();
|
||||
this.edgeModel.Clear ();
|
||||
}
|
||||
|
||||
@ -236,6 +258,26 @@ export class ViewerMainModel
|
||||
});
|
||||
}
|
||||
|
||||
EnumerateLines (enumerator)
|
||||
{
|
||||
this.mainModel.Traverse ((obj) => {
|
||||
if (obj.isLineSegments) {
|
||||
enumerator (obj);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
EnumerateMeshesAndLines (enumerator)
|
||||
{
|
||||
this.mainModel.Traverse ((obj) => {
|
||||
if (obj.isMesh) {
|
||||
enumerator (obj);
|
||||
} else if (obj.isLineSegments) {
|
||||
enumerator (obj);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
EnumerateEdges (enumerator)
|
||||
{
|
||||
this.edgeModel.Traverse ((obj) => {
|
||||
@ -245,8 +287,36 @@ export class ViewerMainModel
|
||||
});
|
||||
}
|
||||
|
||||
HasLinesOrEdges ()
|
||||
{
|
||||
return this.hasLines || this.edgeSettings.showEdges;
|
||||
}
|
||||
|
||||
UpdatePolygonOffset ()
|
||||
{
|
||||
let needPolygonOffset = this.HasLinesOrEdges ();
|
||||
if (needPolygonOffset !== this.hasPolygonOffset) {
|
||||
this.EnumerateMeshes ((mesh) => {
|
||||
SetThreeMeshPolygonOffset (mesh, needPolygonOffset);
|
||||
});
|
||||
this.hasPolygonOffset = needPolygonOffset;
|
||||
}
|
||||
}
|
||||
|
||||
GetMeshIntersectionUnderMouse (mouseCoords, camera, width, height)
|
||||
{
|
||||
function CalculateLineThreshold (mousePos, camera, boundingBoxCenter)
|
||||
{
|
||||
let thresholdInScreenCoordinates = 15.0;
|
||||
let frustumRange = camera.far - camera.near;
|
||||
let cameraDistanceFromCenter = boundingBoxCenter.distanceTo (camera.position);
|
||||
let distanceInFrustumRatio = cameraDistanceFromCenter / frustumRange;
|
||||
let zValue = -1.0 + 2.0 * distanceInFrustumRatio;
|
||||
let referencePoint1 = new THREE.Vector3 (mousePos.x, mousePos.y, zValue).unproject (camera);
|
||||
let referencePoint2 = new THREE.Vector3 (mousePos.x + thresholdInScreenCoordinates, mousePos.y, zValue).unproject (camera);
|
||||
return referencePoint1.distanceTo (referencePoint2);
|
||||
}
|
||||
|
||||
if (this.mainModel.IsEmpty ()) {
|
||||
return null;
|
||||
}
|
||||
@ -255,15 +325,25 @@ export class ViewerMainModel
|
||||
return null;
|
||||
}
|
||||
|
||||
let raycaster = new THREE.Raycaster ();
|
||||
let mousePos = new THREE.Vector2 ();
|
||||
mousePos.x = (mouseCoords.x / width) * 2 - 1;
|
||||
mousePos.y = -(mouseCoords.y / height) * 2 + 1;
|
||||
|
||||
let raycaster = new THREE.Raycaster ();
|
||||
if (this.hasLines) {
|
||||
let boundingBox = this.GetFullBoundingBox ();
|
||||
if (boundingBox !== null) {
|
||||
let boundingBoxCenter = new THREE.Vector3 (0.0, 0.0, 0.0);
|
||||
boundingBox.getCenter (boundingBoxCenter);
|
||||
raycaster.params.Line.threshold = CalculateLineThreshold (mousePos, camera, boundingBoxCenter);
|
||||
}
|
||||
}
|
||||
|
||||
raycaster.setFromCamera (mousePos, camera);
|
||||
let iSectObjects = raycaster.intersectObject (this.mainModel.GetRootObject (), true);
|
||||
for (let i = 0; i < iSectObjects.length; i++) {
|
||||
let iSectObject = iSectObjects[i];
|
||||
if (iSectObject.object.isMesh && iSectObject.object.visible) {
|
||||
if ((iSectObject.object.isMesh || iSectObject.object.isLineSegments) && iSectObject.object.visible) {
|
||||
return iSectObject;
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,6 +68,10 @@ export class Embed
|
||||
if (defaultColor !== null) {
|
||||
settings.defaultColor = defaultColor;
|
||||
}
|
||||
let defaultLineColor = this.hashHandler.GetDefaultLineColorFromHash ();
|
||||
if (defaultLineColor !== null) {
|
||||
settings.defaultLineColor = defaultLineColor;
|
||||
}
|
||||
let inputFiles = InputFilesFromUrls (urls);
|
||||
this.modelLoaderUI.LoadModel (inputFiles, settings, {
|
||||
onStart : () =>
|
||||
|
||||
@ -72,6 +72,12 @@ export class HashHandler
|
||||
return parser.GetDefaultColor ();
|
||||
}
|
||||
|
||||
GetDefaultLineColorFromHash ()
|
||||
{
|
||||
let parser = CreateUrlParser (this.GetHash ());
|
||||
return parser.GetDefaultLineColor ();
|
||||
}
|
||||
|
||||
GetEdgeSettingsFromHash ()
|
||||
{
|
||||
let parser = CreateUrlParser (this.GetHash ());
|
||||
|
||||
@ -136,7 +136,7 @@ export class MeasureTool
|
||||
Click (mouseCoordinates)
|
||||
{
|
||||
let intersection = this.viewer.GetMeshIntersectionUnderMouse (mouseCoordinates);
|
||||
if (intersection === null) {
|
||||
if (intersection === null || !intersection.object.isMesh) {
|
||||
this.ClearMarkers ();
|
||||
this.UpdatePanel ();
|
||||
return;
|
||||
@ -153,7 +153,7 @@ export class MeasureTool
|
||||
MouseMove (mouseCoordinates)
|
||||
{
|
||||
let intersection = this.viewer.GetMeshIntersectionUnderMouse (mouseCoordinates);
|
||||
if (intersection === null) {
|
||||
if (intersection === null || !intersection.object.isMesh) {
|
||||
if (this.tempMarker !== null) {
|
||||
this.tempMarker.Show (false);
|
||||
this.viewer.Render ();
|
||||
|
||||
@ -18,9 +18,11 @@ export class Settings
|
||||
this.backgroundIsEnvMap = false;
|
||||
if (this.themeId === Theme.Light) {
|
||||
this.backgroundColor = new RGBAColor (255, 255, 255, 255);
|
||||
this.defaultLineColor = new RGBColor (100, 100, 100);
|
||||
this.defaultColor = new RGBColor (200, 200, 200);
|
||||
} else if (this.themeId === Theme.Dark) {
|
||||
this.backgroundColor = new RGBAColor (42, 43, 46, 255);
|
||||
this.defaultLineColor = new RGBColor (100, 100, 100);
|
||||
this.defaultColor = new RGBColor (200, 200, 200);
|
||||
}
|
||||
this.edgeSettings = new EdgeSettings (false, new RGBColor (0, 0, 0), 1);
|
||||
@ -32,6 +34,7 @@ export class Settings
|
||||
this.environmentMapName = CookieGetStringVal ('ov_environment_map', 'fishermans_bastion');
|
||||
this.backgroundIsEnvMap = CookieGetBoolVal ('ov_background_is_envmap', false);
|
||||
this.backgroundColor = CookieGetRGBAColorVal ('ov_background_color', new RGBAColor (255, 255, 255, 255));
|
||||
this.defaultLineColor = CookieGetRGBColorVal ('ov_default_line_color', new RGBColor (100, 100, 100));
|
||||
this.defaultColor = CookieGetRGBColorVal ('ov_default_color', new RGBColor (200, 200, 200));
|
||||
this.edgeSettings.showEdges = CookieGetBoolVal ('ov_show_edges', false);
|
||||
this.edgeSettings.edgeColor = CookieGetRGBColorVal ('ov_edge_color', new RGBColor (0, 0, 0));
|
||||
@ -44,6 +47,7 @@ export class Settings
|
||||
CookieSetStringVal ('ov_environment_map', this.environmentMapName);
|
||||
CookieSetBoolVal ('ov_background_is_envmap', this.backgroundIsEnvMap);
|
||||
CookieSetRGBAColorVal ('ov_background_color', this.backgroundColor);
|
||||
CookieSetRGBColorVal ('ov_default_line_color', this.defaultLineColor);
|
||||
CookieSetRGBColorVal ('ov_default_color', this.defaultColor);
|
||||
CookieSetBoolVal ('ov_show_edges', this.edgeSettings.showEdges);
|
||||
CookieSetRGBColorVal ('ov_edge_color', this.edgeSettings.edgeColor);
|
||||
|
||||
@ -71,6 +71,7 @@ export function ShowSharingDialog (fileList, settings, viewer)
|
||||
builder.AddEnvironmentSettings (environmentSettings);
|
||||
builder.AddBackgroundColor (settings.backgroundColor);
|
||||
builder.AddDefaultColor (settings.defaultColor);
|
||||
builder.AddDefaultLineColor (settings.defaultLineColor);
|
||||
builder.AddEdgeSettings (settings.edgeSettings);
|
||||
}
|
||||
let hashParameters = builder.GetParameterList ();
|
||||
|
||||
@ -48,8 +48,8 @@ export class Sidebar
|
||||
getProjectionMode : () => {
|
||||
return this.callbacks.getProjectionMode ();
|
||||
},
|
||||
hasDefaultMaterial : () => {
|
||||
return this.callbacks.hasDefaultMaterial ();
|
||||
getDefaultMaterials : () => {
|
||||
return this.callbacks.getDefaultMaterials ();
|
||||
},
|
||||
onEnvironmentMapChanged : () => {
|
||||
this.callbacks.onEnvironmentMapChanged ();
|
||||
|
||||
@ -7,7 +7,7 @@ import { AddDiv, AddDomElement, ClearDomElement } from '../engine/viewer/domutil
|
||||
import { SidebarPanel } from './sidebarpanel.js';
|
||||
import { CreateInlineColorCircle } from './utils.js';
|
||||
import { GetFileName, IsUrl } from '../engine/io/fileutils.js';
|
||||
import { MaterialType } from '../engine/model/material.js';
|
||||
import { MaterialSource, MaterialType } from '../engine/model/material.js';
|
||||
import { RGBColorToHexString } from '../engine/model/color.js';
|
||||
import { Unit } from '../engine/model/unit.js';
|
||||
|
||||
@ -53,7 +53,14 @@ export class SidebarDetailsPanel extends SidebarPanel
|
||||
let size = SubCoord3D (boundingBox.max, boundingBox.min);
|
||||
let unit = model.GetUnit ();
|
||||
this.AddProperty (table, new Property (PropertyType.Integer, 'Vertices', object3D.VertexCount ()));
|
||||
this.AddProperty (table, new Property (PropertyType.Integer, 'Triangles', object3D.TriangleCount ()));
|
||||
let lineSegmentCount = object3D.LineSegmentCount ();
|
||||
if (lineSegmentCount > 0) {
|
||||
this.AddProperty (table, new Property (PropertyType.Integer, 'Lines', lineSegmentCount));
|
||||
}
|
||||
let triangleCount = object3D.TriangleCount ();
|
||||
if (triangleCount > 0) {
|
||||
this.AddProperty (table, new Property (PropertyType.Integer, 'Triangles', triangleCount));
|
||||
}
|
||||
if (unit !== Unit.Unknown) {
|
||||
this.AddProperty (table, new Property (PropertyType.Text, 'Unit', UnitToString (unit)));
|
||||
}
|
||||
@ -104,7 +111,8 @@ export class SidebarDetailsPanel extends SidebarPanel
|
||||
} else if (material.type === MaterialType.Physical) {
|
||||
typeString = 'Physical';
|
||||
}
|
||||
this.AddProperty (table, new Property (PropertyType.Text, 'Source', material.isDefault ? 'Default' : 'Model'));
|
||||
let materialSource = (material.source !== MaterialSource.Model) ? 'Default' : 'Model';
|
||||
this.AddProperty (table, new Property (PropertyType.Text, 'Source', materialSource));
|
||||
this.AddProperty (table, new Property (PropertyType.Text, 'Type', typeString));
|
||||
if (material.vertexColors) {
|
||||
this.AddProperty (table, new Property (PropertyType.Text, 'Color', 'Vertex colors'));
|
||||
|
||||
@ -10,6 +10,7 @@ import { ProjectionMode } from '../engine/viewer/camera.js';
|
||||
|
||||
import * as Pickr from '@simonwep/pickr';
|
||||
import '@simonwep/pickr/dist/themes/monolith.min.css';
|
||||
import { MaterialSource } from '../engine/main.js';
|
||||
|
||||
function AddColorPicker (parentDiv, opacity, defaultColor, predefinedColors, onChange)
|
||||
{
|
||||
@ -375,22 +376,35 @@ class SettingsImportParametersSection extends SettingsSection
|
||||
constructor (parentDiv, settings)
|
||||
{
|
||||
super (parentDiv, 'Import Settings', settings);
|
||||
this.defaultColorPickerDiv = null;
|
||||
this.defaultLineColorPickerDiv = null;
|
||||
this.defaultColorPicker = null;
|
||||
this.defaultLineColorPicker = null;
|
||||
}
|
||||
|
||||
Init (callbacks)
|
||||
{
|
||||
super.Init (callbacks);
|
||||
function AddDefaultColorPicker (contentDiv, name, defaultColor, onChange)
|
||||
{
|
||||
let colorDiv = AddDiv (contentDiv, 'ov_sidebar_parameter');
|
||||
let colorInput = AddDiv (colorDiv, 'ov_color_picker');
|
||||
AddDiv (colorDiv, null, name);
|
||||
let predefinedDefaultColors = ['#ffffff', '#e3e3e3', '#cc3333', '#fac832', '#4caf50', '#3393bd', '#9b27b0', '#fda4b8'];
|
||||
let defaultColorStr = '#' + RGBColorToHexString (defaultColor);
|
||||
return AddColorPicker (colorInput, false, defaultColorStr, predefinedDefaultColors, onChange);
|
||||
}
|
||||
|
||||
let defaultColorDiv = AddDiv (this.contentDiv, 'ov_sidebar_parameter');
|
||||
let defaultColorInput = AddDiv (defaultColorDiv, 'ov_color_picker');
|
||||
AddDiv (defaultColorDiv, null, 'Default Color');
|
||||
let predefinedDefaultColors = ['#ffffff', '#e3e3e3', '#cc3333', '#fac832', '#4caf50', '#3393bd', '#9b27b0', '#fda4b8'];
|
||||
let defaultColor = '#' + RGBColorToHexString (this.settings.defaultColor);
|
||||
this.defaultColorPicker = AddColorPicker (defaultColorInput, false, defaultColor, predefinedDefaultColors, (r, g, b, a) => {
|
||||
super.Init (callbacks);
|
||||
this.defaultColorPickerDiv = AddDiv (this.contentDiv);
|
||||
this.defaultColorPicker = AddDefaultColorPicker (this.defaultColorPickerDiv, 'Default Color', this.settings.defaultColor, (r, g, b, a) => {
|
||||
this.settings.defaultColor = new RGBColor (r, g, b);
|
||||
this.callbacks.onDefaultColorChanged ();
|
||||
});
|
||||
this.defaultLineColorPickerDiv = AddDiv (this.contentDiv);
|
||||
this.defaultLineColorPicker = AddDefaultColorPicker (this.defaultLineColorPickerDiv, 'Default Line Color', this.settings.defaultLineColor, (r, g, b, a) => {
|
||||
this.settings.defaultLineColor = new RGBColor (r, g, b);
|
||||
this.callbacks.onDefaultColorChanged ();
|
||||
});
|
||||
}
|
||||
|
||||
Update ()
|
||||
@ -398,13 +412,26 @@ class SettingsImportParametersSection extends SettingsSection
|
||||
if (this.defaultColorPicker !== null) {
|
||||
this.defaultColorPicker.setColor ('#' + RGBColorToHexString (this.settings.defaultColor));
|
||||
}
|
||||
if (this.defaultLineColorPicker !== null) {
|
||||
this.defaultLineColorPicker.setColor ('#' + RGBColorToHexString (this.settings.defaultLineColor));
|
||||
}
|
||||
}
|
||||
|
||||
UpdateVisibility ()
|
||||
{
|
||||
if (this.contentDiv !== null) {
|
||||
let hasDefaultMaterial = this.callbacks.hasDefaultMaterial ();
|
||||
ShowDomElement (this.contentDiv, hasDefaultMaterial);
|
||||
let defaultMaterials = this.callbacks.getDefaultMaterials ();
|
||||
if (defaultMaterials.length === 0) {
|
||||
ShowDomElement (this.contentDiv, false);
|
||||
} else {
|
||||
let sources = new Set ();
|
||||
for (let material of defaultMaterials) {
|
||||
sources.add (material.source);
|
||||
}
|
||||
ShowDomElement (this.contentDiv, true);
|
||||
ShowDomElement (this.defaultColorPickerDiv, sources.has (MaterialSource.DefaultFace));
|
||||
ShowDomElement (this.defaultLineColorPickerDiv, sources.has (MaterialSource.DefaultLine));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -413,6 +440,9 @@ class SettingsImportParametersSection extends SettingsSection
|
||||
if (this.defaultColorPicker !== null) {
|
||||
this.defaultColorPicker.hide ();
|
||||
}
|
||||
if (this.defaultLineColorPicker !== null) {
|
||||
this.defaultLineColorPicker.hide ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -482,8 +512,8 @@ export class SidebarSettingsPanel extends SidebarPanel
|
||||
}
|
||||
});
|
||||
this.importParametersSection.Init ({
|
||||
hasDefaultMaterial : () => {
|
||||
return this.callbacks.hasDefaultMaterial ();
|
||||
getDefaultMaterials : () => {
|
||||
return this.callbacks.getDefaultMaterials ();
|
||||
},
|
||||
onDefaultColorChanged : () => {
|
||||
this.callbacks.onDefaultColorChanged ();
|
||||
@ -511,6 +541,7 @@ export class SidebarSettingsPanel extends SidebarPanel
|
||||
this.settings.environmentMapName = defaultSettings.environmentMapName;
|
||||
this.settings.backgroundIsEnvMap = defaultSettings.backgroundIsEnvMap;
|
||||
this.settings.backgroundColor = defaultSettings.backgroundColor;
|
||||
this.settings.defaultLineColor = defaultSettings.defaultLineColor;
|
||||
this.settings.defaultColor = defaultSettings.defaultColor;
|
||||
this.settings.edgeSettings = defaultSettings.edgeSettings;
|
||||
this.settings.themeId = defaultSettings.themeId;
|
||||
|
||||
@ -19,7 +19,7 @@ import { ShowSnapshotDialog } from './snapshotdialog.js';
|
||||
import { AddSvgIconElement, GetFilesFromDataTransfer, InstallTooltip, IsSmallWidth } from './utils.js';
|
||||
import { ShowOpenUrlDialog } from './openurldialog.js';
|
||||
import { ShowSharingDialog } from './sharingdialog.js';
|
||||
import { HasDefaultMaterial, ReplaceDefaultMaterialColor } from '../engine/model/modelutils.js';
|
||||
import { GetDefaultMaterials, ReplaceDefaultMaterialsColor } from '../engine/model/modelutils.js';
|
||||
import { Direction } from '../engine/geometry/geometry.js';
|
||||
import { CookieGetBoolVal, CookieSetBoolVal } from './cookiehandler.js';
|
||||
import { MeasureTool } from './measuretool.js';
|
||||
@ -402,6 +402,7 @@ export class Website
|
||||
}
|
||||
TransformFileHostUrls (urls);
|
||||
let importSettings = new ImportSettings ();
|
||||
importSettings.defaultLineColor = this.settings.defaultLineColor;
|
||||
importSettings.defaultColor = this.settings.defaultColor;
|
||||
let defaultColor = this.hashHandler.GetDefaultColorFromHash ();
|
||||
if (defaultColor !== null) {
|
||||
@ -480,6 +481,7 @@ export class Website
|
||||
LoadModelFromFileList (files)
|
||||
{
|
||||
let importSettings = new ImportSettings ();
|
||||
importSettings.defaultLineColor = this.settings.defaultLineColor;
|
||||
importSettings.defaultColor = this.settings.defaultColor;
|
||||
let inputFiles = InputFilesFromFileObjects (files);
|
||||
this.LoadModelFromInputFiles (inputFiles, importSettings);
|
||||
@ -572,14 +574,15 @@ export class Website
|
||||
if (resetColors) {
|
||||
let defaultSettings = new Settings (this.settings.themeId);
|
||||
this.settings.backgroundColor = defaultSettings.backgroundColor;
|
||||
this.settings.defaultLineColor = defaultSettings.defaultLineColor;
|
||||
this.settings.defaultColor = defaultSettings.defaultColor;
|
||||
this.sidebar.UpdateControlsStatus ();
|
||||
|
||||
this.viewer.SetBackgroundColor (this.settings.backgroundColor);
|
||||
let modelLoader = this.modelLoaderUI.GetModelLoader ();
|
||||
if (modelLoader.GetDefaultMaterial () !== null) {
|
||||
ReplaceDefaultMaterialColor (this.model, this.settings.defaultColor);
|
||||
modelLoader.ReplaceDefaultMaterialColor (this.settings.defaultColor);
|
||||
if (modelLoader.GetDefaultMaterials () !== null) {
|
||||
ReplaceDefaultMaterialsColor (this.model, this.settings.defaultColor, this.settings.defaultLineColor);
|
||||
modelLoader.ReplaceDefaultMaterialsColor (this.settings.defaultColor, this.settings.defaultLineColor);
|
||||
}
|
||||
}
|
||||
|
||||
@ -794,8 +797,8 @@ export class Website
|
||||
getProjectionMode : () => {
|
||||
return this.viewer.GetProjectionMode ();
|
||||
},
|
||||
hasDefaultMaterial : () => {
|
||||
return HasDefaultMaterial (this.model);
|
||||
getDefaultMaterials : () => {
|
||||
return GetDefaultMaterials (this.model);
|
||||
},
|
||||
onEnvironmentMapChanged : () => {
|
||||
this.settings.SaveToCookies ();
|
||||
@ -814,9 +817,9 @@ export class Website
|
||||
onDefaultColorChanged : () => {
|
||||
this.settings.SaveToCookies ();
|
||||
let modelLoader = this.modelLoaderUI.GetModelLoader ();
|
||||
if (modelLoader.GetDefaultMaterial () !== null) {
|
||||
ReplaceDefaultMaterialColor (this.model, this.settings.defaultColor);
|
||||
modelLoader.ReplaceDefaultMaterialColor (this.settings.defaultColor);
|
||||
if (modelLoader.GetDefaultMaterials () !== null) {
|
||||
ReplaceDefaultMaterialsColor (this.model, this.settings.defaultColor, this.settings.defaultLineColor);
|
||||
modelLoader.ReplaceDefaultMaterialsColor (this.settings.defaultColor, this.settings.defaultLineColor);
|
||||
}
|
||||
this.viewer.Render ();
|
||||
},
|
||||
@ -836,21 +839,21 @@ export class Website
|
||||
|
||||
InitNavigator ()
|
||||
{
|
||||
function GetMeshUserData (viewer, meshInstanceId)
|
||||
function GetMeshUserDataArray (viewer, meshInstanceId)
|
||||
{
|
||||
let userData = null;
|
||||
viewer.EnumerateMeshesUserData ((meshUserData) => {
|
||||
let userDataArr = [];
|
||||
viewer.EnumerateMeshesAndLinesUserData ((meshUserData) => {
|
||||
if (meshUserData.originalMeshInstance.id.IsEqual (meshInstanceId)) {
|
||||
userData = meshUserData;
|
||||
userDataArr.push (meshUserData);
|
||||
}
|
||||
});
|
||||
return userData;
|
||||
return userDataArr;
|
||||
}
|
||||
|
||||
function GetMeshesForMaterial (viewer, materialIndex)
|
||||
{
|
||||
let usedByMeshes = [];
|
||||
viewer.EnumerateMeshesUserData ((meshUserData) => {
|
||||
viewer.EnumerateMeshesAndLinesUserData ((meshUserData) => {
|
||||
if (materialIndex === null || meshUserData.originalMaterials.indexOf (materialIndex) !== -1) {
|
||||
usedByMeshes.push (meshUserData.originalMeshInstance);
|
||||
}
|
||||
@ -876,10 +879,16 @@ export class Website
|
||||
usedMaterials.push (GetMaterialReferenceInfo (model, materialIndex));
|
||||
}
|
||||
} else {
|
||||
let userData = GetMeshUserData (viewer, meshInstanceId);
|
||||
for (let i = 0; i < userData.originalMaterials.length; i++) {
|
||||
const materialIndex = userData.originalMaterials[i];
|
||||
usedMaterials.push (GetMaterialReferenceInfo (model, materialIndex));
|
||||
let userDataArr = GetMeshUserDataArray (viewer, meshInstanceId);
|
||||
let addedMaterialIndices = new Set ();
|
||||
for (let userData of userDataArr) {
|
||||
for (let materialIndex of userData.originalMaterials) {
|
||||
if (addedMaterialIndices.has (materialIndex)) {
|
||||
continue;
|
||||
}
|
||||
usedMaterials.push (GetMaterialReferenceInfo (model, materialIndex));
|
||||
addedMaterialIndices.add (materialIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
usedMaterials.sort ((a, b) => {
|
||||
|
||||
9
test/testfiles/obj/cube_with_edges.mtl
Normal file
9
test/testfiles/obj/cube_with_edges.mtl
Normal file
@ -0,0 +1,9 @@
|
||||
newmtl Red
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.800000 0.000000 0.000000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
|
||||
newmtl Blue
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.000000 0.000000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
43
test/testfiles/obj/cube_with_edges.obj
Normal file
43
test/testfiles/obj/cube_with_edges.obj
Normal file
@ -0,0 +1,43 @@
|
||||
# Cube with Materials
|
||||
|
||||
mtllib cube_with_edges.mtl
|
||||
|
||||
g Cube
|
||||
|
||||
v 0.0 0.0 0.0
|
||||
v 1.0 0.0 0.0
|
||||
v 1.0 1.0 0.0
|
||||
v 0.0 1.0 0.0
|
||||
v 0.0 0.0 1.0
|
||||
v 1.0 0.0 1.0
|
||||
v 1.0 1.0 1.0
|
||||
v 0.0 1.0 1.0
|
||||
|
||||
vn 1.0 0.0 0.0
|
||||
vn -1.0 0.0 0.0
|
||||
vn 0.0 1.0 0.0
|
||||
vn 0.0 -1.0 0.0
|
||||
vn 0.0 0.0 1.0
|
||||
vn 0.0 0.0 -1.0
|
||||
|
||||
vt 0.0 0.0
|
||||
vt 1.0 0.0
|
||||
vt 1.0 1.0
|
||||
vt 0.0 1.0
|
||||
|
||||
f 1/1/6 4/2/6 3/3/6 2/4/6
|
||||
f 2/1/1 3/2/1 7/3/1 6/4/1
|
||||
f 4/1/2 1/2/2 5/3/2 8/4/2
|
||||
f 5/1/5 6/2/5 7/3/5 8/4/5
|
||||
l 1 4
|
||||
l 2 3
|
||||
l 6 7
|
||||
l 5 8
|
||||
|
||||
usemtl Red
|
||||
f 3/1/3 4/2/3 8/3/3 7/4/3
|
||||
l 1 2 6 5 1
|
||||
|
||||
usemtl Blue
|
||||
f 1/1/4 2/2/4 6/3/4 5/4/4
|
||||
l 3 4 8 7 3
|
||||
11
test/testfiles/obj/lines.obj
Normal file
11
test/testfiles/obj/lines.obj
Normal file
@ -0,0 +1,11 @@
|
||||
v 0.0 0.0 0.0
|
||||
v 1.0 0.0 0.0
|
||||
v 1.0 1.0 0.0
|
||||
v 0.0 1.0 0.0
|
||||
v 0.0 0.0 1.0
|
||||
v 1.0 0.0 1.0
|
||||
v 1.0 1.0 1.0
|
||||
v 0.0 1.0 1.0
|
||||
l 1 2
|
||||
l 3 4
|
||||
l 5 6 7 8 5
|
||||
14
test/testfiles/obj/lines_colors.mtl
Normal file
14
test/testfiles/obj/lines_colors.mtl
Normal file
@ -0,0 +1,14 @@
|
||||
newmtl Red
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.800000 0.200000 0.200000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
|
||||
newmtl Green
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.152940 0.607840 0.380390
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
|
||||
newmtl Blue
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.000000 0.541180 0.721570
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
18
test/testfiles/obj/lines_colors.obj
Normal file
18
test/testfiles/obj/lines_colors.obj
Normal file
@ -0,0 +1,18 @@
|
||||
mtllib lines_colors.mtl
|
||||
|
||||
v 0.0 0.0 0.0
|
||||
v 1.0 0.0 0.0
|
||||
v 1.0 1.0 0.0
|
||||
v 0.0 1.0 0.0
|
||||
v 0.0 0.0 1.0
|
||||
v 1.0 0.0 1.0
|
||||
v 1.0 1.0 1.0
|
||||
v 0.0 1.0 1.0
|
||||
usemtl Red
|
||||
l 1 2
|
||||
l 3 4
|
||||
usemtl Green
|
||||
l 5 6 7 8 5
|
||||
usemtl Blue
|
||||
l 1 5
|
||||
|
||||
13
test/testfiles/obj/lines_in_meshes.obj
Normal file
13
test/testfiles/obj/lines_in_meshes.obj
Normal file
@ -0,0 +1,13 @@
|
||||
v 0.0 0.0 0.0
|
||||
v 1.0 0.0 0.0
|
||||
v 1.0 1.0 0.0
|
||||
v 0.0 1.0 0.0
|
||||
v 0.0 0.0 1.0
|
||||
v 1.0 0.0 1.0
|
||||
v 1.0 1.0 1.0
|
||||
v 0.0 1.0 1.0
|
||||
g Mesh01
|
||||
l 1 2
|
||||
l 3 4
|
||||
g Mesh02
|
||||
l 5 6 7 8 5
|
||||
16
test/testfiles/obj/lines_in_meshes_2.obj
Normal file
16
test/testfiles/obj/lines_in_meshes_2.obj
Normal file
@ -0,0 +1,16 @@
|
||||
v 0.0 0.0 0.0
|
||||
v 1.0 0.0 0.0
|
||||
v 1.0 1.0 0.0
|
||||
v 0.0 1.0 0.0
|
||||
|
||||
g Mesh01
|
||||
l 1 2
|
||||
l 3 4
|
||||
|
||||
v 0.0 0.0 1.0
|
||||
v 1.0 0.0 1.0
|
||||
v 1.0 1.0 1.0
|
||||
v 0.0 1.0 1.0
|
||||
|
||||
g Mesh02
|
||||
l 5 6 7 8 5
|
||||
14
test/testfiles/obj/lines_triangles_colors.mtl
Normal file
14
test/testfiles/obj/lines_triangles_colors.mtl
Normal file
@ -0,0 +1,14 @@
|
||||
newmtl Red
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.800000 0.200000 0.200000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
|
||||
newmtl Green
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.152940 0.607840 0.380390
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
|
||||
newmtl Blue
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.000000 0.541180 0.721570
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
50
test/testfiles/obj/lines_triangles_colors.obj
Normal file
50
test/testfiles/obj/lines_triangles_colors.obj
Normal file
@ -0,0 +1,50 @@
|
||||
mtllib lines_triangles_colors.mtl
|
||||
|
||||
v 0.0 0.0 0.0
|
||||
v 1.0 0.0 0.0
|
||||
v 1.0 0.0 1.0
|
||||
v 0.0 0.0 1.0
|
||||
v 0.5 1.0 0.5
|
||||
|
||||
g Mesh01
|
||||
usemtl Red
|
||||
f 1 2 3
|
||||
l 1 5
|
||||
usemtl Green
|
||||
f 1 3 4
|
||||
l 3 5
|
||||
|
||||
v 2.0 0.0 0.0
|
||||
v 3.0 0.0 0.0
|
||||
v 3.0 0.0 1.0
|
||||
v 2.0 0.0 1.0
|
||||
v 2.5 1.0 0.5
|
||||
|
||||
g Mesh02
|
||||
usemtl Red
|
||||
f 6 7 8
|
||||
l 6 10
|
||||
usemtl Green
|
||||
f 6 8 9
|
||||
l 8 10
|
||||
|
||||
v 4.0 0.0 0.0
|
||||
v 5.0 0.0 0.0
|
||||
v 5.0 0.0 1.0
|
||||
v 4.0 0.0 1.0
|
||||
|
||||
g Mesh03
|
||||
usemtl Red
|
||||
f 11 12 13
|
||||
usemtl Green
|
||||
f 11 13 14
|
||||
|
||||
v 6.0 0.0 0.0
|
||||
v 7.0 0.0 1.0
|
||||
v 6.5 1.0 0.5
|
||||
|
||||
g Mesh04
|
||||
usemtl Red
|
||||
l 15 17
|
||||
usemtl Green
|
||||
l 16 17
|
||||
11
test/testfiles/obj/lines_with_vt.obj
Normal file
11
test/testfiles/obj/lines_with_vt.obj
Normal file
@ -0,0 +1,11 @@
|
||||
v 0.0 0.0 0.0
|
||||
v 1.0 0.0 0.0
|
||||
v 1.0 1.0 0.0
|
||||
v 0.0 1.0 0.0
|
||||
v 0.0 0.0 1.0
|
||||
v 1.0 0.0 1.0
|
||||
v 1.0 1.0 1.0
|
||||
v 0.0 1.0 1.0
|
||||
l 1/1 2/2
|
||||
l 3/3 4/4
|
||||
l 5/5 6/6 7/7 8/8 5/5
|
||||
@ -219,6 +219,9 @@ describe ('Exporter', function () {
|
||||
let contentBuffer = stlFile.GetBufferContent ();
|
||||
let importer = new OV.ImporterStl ();
|
||||
importer.Import (stlFile.GetName (), 'stl', contentBuffer, {
|
||||
getDefaultLineMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
getDefaultMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
@ -316,6 +319,9 @@ describe ('Exporter', function () {
|
||||
let contentBuffer = plyFile.GetBufferContent ();
|
||||
let importer = new OV.ImporterPly ();
|
||||
importer.Import (plyFile.GetName (), 'ply', contentBuffer, {
|
||||
getDefaultLineMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
getDefaultMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
@ -347,6 +353,9 @@ describe ('Exporter', function () {
|
||||
let contentBuffer = gltfFile.GetBufferContent ();
|
||||
let importer = new OV.ImporterGltf ();
|
||||
importer.Import (gltfFile.GetName (), 'gltf', contentBuffer, {
|
||||
getDefaultLineMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
getDefaultMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
@ -383,6 +392,9 @@ describe ('Exporter', function () {
|
||||
let contentBuffer = glbFile.GetBufferContent ();
|
||||
let importer = new OV.ImporterGltf ();
|
||||
importer.Import (glbFile.GetName (), 'glb', contentBuffer, {
|
||||
getDefaultLineMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
getDefaultMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
@ -416,6 +428,9 @@ describe ('Exporter', function () {
|
||||
let contentBuffer = glbFile.GetBufferContent ();
|
||||
let importer = new OV.ImporterGltf ();
|
||||
importer.Import (glbFile.GetName (), 'glb', contentBuffer, {
|
||||
getDefaultLineMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
getDefaultMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
@ -451,6 +466,9 @@ describe ('Exporter', function () {
|
||||
let contentBuffer = glbFile.GetBufferContent ();
|
||||
let importer = new OV.ImporterGltf ();
|
||||
importer.Import (glbFile.GetName (), 'glb', contentBuffer, {
|
||||
getDefaultLineMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
getDefaultMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
@ -486,6 +504,9 @@ describe ('Exporter', function () {
|
||||
let contentBuffer = glbFile.GetBufferContent ();
|
||||
let importer = new OV.ImporterGltf ();
|
||||
importer.Import (glbFile.GetName (), 'glb', contentBuffer, {
|
||||
getDefaultLineMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
getDefaultMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
@ -521,6 +542,9 @@ describe ('Exporter', function () {
|
||||
let contentBuffer = glbFile.GetBufferContent ();
|
||||
let importer = new OV.ImporterGltf ();
|
||||
importer.Import (glbFile.GetName (), 'glb', contentBuffer, {
|
||||
getDefaultLineMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
getDefaultMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
|
||||
@ -119,14 +119,12 @@ function ExportImport (model, format, extension, onReady)
|
||||
let fileObjects = exportedFiles.map (file => new OV.InputFile (file.name, OV.FileSource.File, new FileObject ('', file.name, file.content)));
|
||||
importer.ImportFiles (fileObjects, settings, {
|
||||
onLoadStart : function () {
|
||||
|
||||
},
|
||||
onFileListProgress : (current, total) => {
|
||||
},
|
||||
onFileLoadProgress : (current, total) => {
|
||||
},
|
||||
onImportStart : function () {
|
||||
|
||||
},
|
||||
onImportSuccess : function (importResult) {
|
||||
onReady (importResult.model)
|
||||
@ -152,6 +150,7 @@ function CheckSingleMeshModel (model, model2)
|
||||
assert.strictEqual (model2.MaterialCount (), 1);
|
||||
assert.strictEqual (model2.MeshInstanceCount (), 1);
|
||||
assert.strictEqual (model.TriangleCount (), model2.TriangleCount ());
|
||||
assert.strictEqual (model.LineSegmentCount (), model2.LineSegmentCount ());
|
||||
CheckModelBounds (model, model2);
|
||||
}
|
||||
|
||||
@ -160,6 +159,7 @@ function CheckModel (model, model2)
|
||||
assert.strictEqual (model.MaterialCount (), model2.MaterialCount ());
|
||||
assert.strictEqual (model.MeshInstanceCount (), model2.MeshInstanceCount ());
|
||||
assert.strictEqual (model.TriangleCount (), model2.TriangleCount ());
|
||||
assert.strictEqual (model.LineSegmentCount (), model2.LineSegmentCount ());
|
||||
CheckModelBounds (model, model2);
|
||||
}
|
||||
|
||||
|
||||
@ -26,6 +26,7 @@ describe ('3ds Importer', function() {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 12,
|
||||
uvCount : 8,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0, 0, 0],
|
||||
@ -57,6 +58,7 @@ describe ('3ds Importer', function() {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 12,
|
||||
uvCount : 8,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0, 0, 0],
|
||||
@ -88,6 +90,7 @@ describe ('3ds Importer', function() {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 12,
|
||||
uvCount : 8,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0, 0, 0],
|
||||
@ -100,6 +103,7 @@ describe ('3ds Importer', function() {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 12,
|
||||
uvCount : 8,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [2, 0, 0],
|
||||
@ -131,6 +135,7 @@ describe ('3ds Importer', function() {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 12,
|
||||
uvCount : 8,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0, 0, 0],
|
||||
@ -143,6 +148,7 @@ describe ('3ds Importer', function() {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 12,
|
||||
uvCount : 8,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [2, 0, 0],
|
||||
@ -155,6 +161,7 @@ describe ('3ds Importer', function() {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 12,
|
||||
uvCount : 8,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [2, 2, 0],
|
||||
@ -167,6 +174,7 @@ describe ('3ds Importer', function() {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 12,
|
||||
uvCount : 8,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0, 2, 0],
|
||||
@ -192,6 +200,7 @@ describe ('3ds Importer', function() {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 12,
|
||||
uvCount: 8,
|
||||
lineCount : 0,
|
||||
triangleCount: 12,
|
||||
boundingBox: { min: [ -1, -1, -1 ], max: [ 1, 1, 1 ] }
|
||||
},
|
||||
@ -201,6 +210,7 @@ describe ('3ds Importer', function() {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 12,
|
||||
uvCount: 8,
|
||||
lineCount : 0,
|
||||
triangleCount: 12,
|
||||
boundingBox: { min: [ 2, -1, -1 ], max: [ 4, 1, 1 ] }
|
||||
},
|
||||
@ -210,6 +220,7 @@ describe ('3ds Importer', function() {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 12,
|
||||
uvCount: 8,
|
||||
lineCount : 0,
|
||||
triangleCount: 12,
|
||||
boundingBox: { min: [ 2, 2, -1 ], max: [ 4, 4, 1 ] }
|
||||
},
|
||||
@ -219,6 +230,7 @@ describe ('3ds Importer', function() {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 12,
|
||||
uvCount: 8,
|
||||
lineCount : 0,
|
||||
triangleCount: 12,
|
||||
boundingBox: { min: [ -1, 2, -1 ], max: [ 1, 4, 1 ] }
|
||||
},
|
||||
@ -228,6 +240,7 @@ describe ('3ds Importer', function() {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 12,
|
||||
uvCount: 8,
|
||||
lineCount : 0,
|
||||
triangleCount: 12,
|
||||
boundingBox: { min: [ -1, -1, 2 ], max: [ 1, 1, 4 ] }
|
||||
},
|
||||
@ -237,6 +250,7 @@ describe ('3ds Importer', function() {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 12,
|
||||
uvCount: 8,
|
||||
lineCount : 0,
|
||||
triangleCount: 12,
|
||||
boundingBox: { min: [ 2, -1, 2 ], max: [ 4, 1, 4 ] }
|
||||
},
|
||||
@ -246,6 +260,7 @@ describe ('3ds Importer', function() {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 12,
|
||||
uvCount: 8,
|
||||
lineCount : 0,
|
||||
triangleCount: 12,
|
||||
boundingBox: { min: [ 2, 2, 2 ], max: [ 4, 4, 4 ] }
|
||||
},
|
||||
@ -255,6 +270,7 @@ describe ('3ds Importer', function() {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 12,
|
||||
uvCount: 8,
|
||||
lineCount : 0,
|
||||
triangleCount: 12,
|
||||
boundingBox: { min: [ -1, 2, 2 ], max: [ 1, 4, 4 ] }
|
||||
}
|
||||
|
||||
@ -277,7 +277,6 @@ describe ('Importer Test', function () {
|
||||
onFileLoadProgress : (current, total) => {
|
||||
},
|
||||
onImportStart : function () {
|
||||
|
||||
},
|
||||
onImportSuccess : function (importResult) {
|
||||
assert.ok (!OV.IsModelEmpty (importResult.model));
|
||||
|
||||
@ -45,6 +45,7 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 1,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 1,
|
||||
boundingBox : {
|
||||
min : [0.0, 0.0, 0.0],
|
||||
@ -102,6 +103,7 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 24,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [-0.5, -0.5, -0.5],
|
||||
@ -158,6 +160,7 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount : 24,
|
||||
normalCount : 24,
|
||||
uvCount : 24,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [-0.5, -0.5, -0.5],
|
||||
@ -214,6 +217,7 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 24,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [-0.5, -0.5, -0.5],
|
||||
@ -270,6 +274,7 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 24,
|
||||
uvCount : 24,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [-0.5, -0.5, -0.5],
|
||||
@ -324,6 +329,7 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 3,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 1,
|
||||
boundingBox : {
|
||||
min : [0.0, 0.0, 0.0],
|
||||
@ -336,6 +342,7 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 3,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 1,
|
||||
boundingBox : {
|
||||
min : [1.0, 0.0, 0.0],
|
||||
@ -381,7 +388,8 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 78,
|
||||
uvCount: 0,
|
||||
triangleCount: 38,
|
||||
lineCount : 0,
|
||||
triangleCount : 38,
|
||||
boundingBox : {
|
||||
min: [ -0.6921195564310951, -1.0785199551363698, -5.330651201963446 ],
|
||||
max: [ 1.0439303242310798, 2.868914373727357, -4.66934876823423 ]
|
||||
@ -393,7 +401,8 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 50,
|
||||
uvCount: 0,
|
||||
triangleCount: 26,
|
||||
lineCount : 0,
|
||||
triangleCount : 26,
|
||||
boundingBox : {
|
||||
min: [ 0.8097413778305054, 2.8717148303985596, -5.33065128326416 ],
|
||||
max: [ 1.4936277866363525, 3.9211390018463135, -4.66934871673584 ]
|
||||
@ -405,7 +414,8 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 50,
|
||||
uvCount: 0,
|
||||
triangleCount: 26,
|
||||
lineCount : 0,
|
||||
triangleCount : 26,
|
||||
boundingBox : {
|
||||
min: [ -1.1686336994171143, -5.330650806427002, 2.93727445602417 ],
|
||||
max: [ -0.46912679076194763, -4.66934871673584, 3.9916374683380127 ]
|
||||
@ -417,7 +427,8 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 78,
|
||||
uvCount: 0,
|
||||
triangleCount: 38,
|
||||
lineCount : 0,
|
||||
triangleCount : 38,
|
||||
boundingBox : {
|
||||
min: [ -0.9557393651589479, -5.330651177643153, -1.06505742884149 ],
|
||||
max: [ 0.6167901044859734, -4.6693486435429055, 2.934442924096579 ]
|
||||
@ -429,7 +440,8 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 78,
|
||||
uvCount: 0,
|
||||
triangleCount: 38,
|
||||
lineCount : 0,
|
||||
triangleCount : 38,
|
||||
boundingBox : {
|
||||
min: [ -5.330651171390089, -1.0326269494863676, -0.6059335185163844 ],
|
||||
max: [ -4.669348828609911, 2.9885841671721116, 0.8202131194767724 ]
|
||||
@ -441,7 +453,8 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 54,
|
||||
uvCount: 0,
|
||||
triangleCount: 26,
|
||||
lineCount : 0,
|
||||
triangleCount : 26,
|
||||
boundingBox : {
|
||||
min: [ -5.33065128326416, 2.991360902786255, -0.012430161237716675 ],
|
||||
max: [ -4.66934871673584, 4.039160251617432, 0.6999828815460205 ]
|
||||
@ -453,7 +466,8 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 52,
|
||||
uvCount: 0,
|
||||
triangleCount: 26,
|
||||
lineCount : 0,
|
||||
triangleCount : 26,
|
||||
boundingBox : {
|
||||
min: [ -1.3648574352264404, 2.9005930423736572, 4.66934871673584 ],
|
||||
max: [ -0.6740907430648804, 3.9529545307159424, 5.33065128326416 ]
|
||||
@ -465,7 +479,8 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 74,
|
||||
uvCount: 0,
|
||||
triangleCount: 38,
|
||||
lineCount : 0,
|
||||
triangleCount : 38,
|
||||
boundingBox : {
|
||||
min: [ -1.009571011381568, -1.074115497823536, 4.669348895549774 ],
|
||||
max: [ 0.6625885973069405, 2.8977772707193465, 5.330651104450226 ]
|
||||
@ -477,7 +492,8 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 54,
|
||||
uvCount: 0,
|
||||
triangleCount: 26,
|
||||
lineCount : 0,
|
||||
triangleCount : 26,
|
||||
boundingBox : {
|
||||
min: [ 4.66934871673584, 2.4595587253570557, -2.553251266479492 ],
|
||||
max: [ 5.33065128326416, 3.432579517364502, -1.7226401567459106 ]
|
||||
@ -489,7 +505,8 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 78,
|
||||
uvCount: 0,
|
||||
triangleCount: 38,
|
||||
lineCount : 0,
|
||||
triangleCount : 38,
|
||||
boundingBox : {
|
||||
min: [ 4.669348835945129, -1.0589144181932033, -1.7207290818192755 ],
|
||||
max: [ 5.330651164054871, 2.4574561383341145, 0.9159925616542917 ]
|
||||
@ -501,7 +518,8 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 52,
|
||||
uvCount: 0,
|
||||
triangleCount: 26,
|
||||
lineCount : 0,
|
||||
triangleCount : 26,
|
||||
boundingBox : {
|
||||
min: [ 2.8218495845794678, 4.669349193572998, -1.6833229064941406 ],
|
||||
max: [ 3.864471435546875, 5.33065128326416, -1.0113166570663452 ]
|
||||
@ -513,7 +531,8 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 78,
|
||||
uvCount: 0,
|
||||
triangleCount: 38,
|
||||
lineCount : 0,
|
||||
triangleCount : 38,
|
||||
boundingBox : {
|
||||
min: [ -1.0826615032554154, 4.669348806142807, -1.093071740019906 ],
|
||||
max: [ 2.8190779754834807, 5.3306513130664825, 0.7348238365226794 ]
|
||||
@ -525,7 +544,8 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount: 0,
|
||||
normalCount: 272,
|
||||
uvCount: 0,
|
||||
triangleCount: 140,
|
||||
lineCount : 0,
|
||||
triangleCount : 140,
|
||||
boundingBox : {
|
||||
min: [ -5.000001907348633, -5, -5.000001907348633 ],
|
||||
max: [ 5.000002384185791, 5, 5.000002861022949 ]
|
||||
@ -566,6 +586,7 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 2,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 2,
|
||||
boundingBox : {
|
||||
min : [-0.5, -0.5, 0.0],
|
||||
@ -603,6 +624,7 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 2,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 2,
|
||||
boundingBox : {
|
||||
min : [-0.5, -0.5, 0.0],
|
||||
@ -641,6 +663,7 @@ describe ('Gltf Importer', function () {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 12,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0.0, 0.0, 0.0],
|
||||
|
||||
@ -18,6 +18,7 @@ describe ('Obj Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -44,6 +45,7 @@ describe ('Obj Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -76,6 +78,7 @@ describe ('Obj Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -108,6 +111,7 @@ describe ('Obj Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : 'MyMeshName',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -134,6 +138,7 @@ describe ('Obj Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -160,6 +165,7 @@ describe ('Obj Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -186,6 +192,7 @@ describe ('Obj Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : 'MeshName',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -212,6 +219,7 @@ describe ('Obj Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : 'MeshName1',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -223,6 +231,7 @@ describe ('Obj Importer', function () {
|
||||
},
|
||||
{
|
||||
name : 'MeshName2',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1],
|
||||
@ -249,6 +258,7 @@ describe ('Obj Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : 'MeshName1',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -260,6 +270,7 @@ describe ('Obj Importer', function () {
|
||||
},
|
||||
{
|
||||
name : 'MeshName2',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1],
|
||||
@ -287,6 +298,7 @@ describe ('Obj Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : 'MeshName',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -314,6 +326,7 @@ describe ('Obj Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : 'MeshName',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -346,6 +359,7 @@ describe ('Obj Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : 'MeshName1',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -357,6 +371,7 @@ describe ('Obj Importer', function () {
|
||||
},
|
||||
{
|
||||
name : 'MeshName2',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 0, 0, 1],
|
||||
@ -383,6 +398,7 @@ describe ('Obj Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : 'MeshName',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -415,6 +431,7 @@ describe ('Obj Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : 'Mesh',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -449,6 +466,7 @@ describe ('Obj Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : 'Mesh',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -489,6 +507,7 @@ describe ('Obj Importer', function () {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 6,
|
||||
uvCount : 4,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0, 0, 0],
|
||||
@ -519,6 +538,7 @@ describe ('Obj Importer', function () {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 6,
|
||||
uvCount : 4,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0, 0, 0],
|
||||
@ -550,6 +570,7 @@ describe ('Obj Importer', function () {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 6,
|
||||
uvCount : 4,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0, 0, 0],
|
||||
@ -581,6 +602,7 @@ describe ('Obj Importer', function () {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 6,
|
||||
uvCount : 4,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0, 0, 0],
|
||||
@ -608,6 +630,7 @@ describe ('Obj Importer', function () {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 20,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 20,
|
||||
boundingBox : {
|
||||
min : [-0.85065080835204, -0.85065080835204, -0.85065080835204],
|
||||
@ -628,6 +651,189 @@ describe ('Obj Importer', function () {
|
||||
done ();
|
||||
});
|
||||
});
|
||||
|
||||
it ('lines.obj', function (done) {
|
||||
ImportObjFile ('lines.obj', function (model) {
|
||||
assert.ok (OV.CheckModel (model));
|
||||
assert.deepStrictEqual (ModelToObject (model), {
|
||||
name : '',
|
||||
materials : [
|
||||
{ name : '' }
|
||||
],
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0],
|
||||
mat : 0
|
||||
},
|
||||
{
|
||||
vertices : [1, 1, 0, 0, 1, 0],
|
||||
mat : 0
|
||||
},
|
||||
{
|
||||
vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1],
|
||||
mat : 0
|
||||
}
|
||||
],
|
||||
triangles : []
|
||||
}
|
||||
]
|
||||
});
|
||||
done ();
|
||||
});
|
||||
});
|
||||
|
||||
it ('lines_with_vt.obj', function (done) {
|
||||
ImportObjFile ('lines_with_vt.obj', function (model) {
|
||||
assert.ok (OV.CheckModel (model));
|
||||
assert.deepStrictEqual (ModelToObject (model), {
|
||||
name : '',
|
||||
materials : [
|
||||
{ name : '' }
|
||||
],
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0],
|
||||
mat : 0
|
||||
},
|
||||
{
|
||||
vertices : [1, 1, 0, 0, 1, 0],
|
||||
mat : 0
|
||||
},
|
||||
{
|
||||
vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1],
|
||||
mat : 0
|
||||
}
|
||||
],
|
||||
triangles : []
|
||||
}
|
||||
]
|
||||
});
|
||||
done ();
|
||||
});
|
||||
});
|
||||
|
||||
it ('lines_in_meshes.obj', function (done) {
|
||||
ImportObjFile ('lines_in_meshes.obj', function (model) {
|
||||
assert.ok (OV.CheckModel (model));
|
||||
assert.deepStrictEqual (ModelToObject (model), {
|
||||
name : '',
|
||||
materials : [
|
||||
{ name : '' }
|
||||
],
|
||||
meshes : [
|
||||
{
|
||||
name : 'Mesh01',
|
||||
lines : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0],
|
||||
mat : 0
|
||||
},
|
||||
{
|
||||
vertices : [1, 1, 0, 0, 1, 0],
|
||||
mat : 0
|
||||
}
|
||||
],
|
||||
triangles : []
|
||||
},
|
||||
{
|
||||
name : 'Mesh02',
|
||||
lines : [
|
||||
{
|
||||
vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1],
|
||||
mat : 0
|
||||
}
|
||||
],
|
||||
triangles : []
|
||||
}
|
||||
]
|
||||
});
|
||||
done ();
|
||||
});
|
||||
});
|
||||
|
||||
it ('lines_in_meshes_2.obj', function (done) {
|
||||
ImportObjFile ('lines_in_meshes_2.obj', function (model) {
|
||||
assert.ok (OV.CheckModel (model));
|
||||
assert.deepStrictEqual (ModelToObject (model), {
|
||||
name : '',
|
||||
materials : [
|
||||
{ name : '' }
|
||||
],
|
||||
meshes : [
|
||||
{
|
||||
name : 'Mesh01',
|
||||
lines : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0],
|
||||
mat : 0
|
||||
},
|
||||
{
|
||||
vertices : [1, 1, 0, 0, 1, 0],
|
||||
mat : 0
|
||||
}
|
||||
],
|
||||
triangles : []
|
||||
},
|
||||
{
|
||||
name : 'Mesh02',
|
||||
lines : [
|
||||
{
|
||||
vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1],
|
||||
mat : 0
|
||||
}
|
||||
],
|
||||
triangles : []
|
||||
}
|
||||
]
|
||||
});
|
||||
done ();
|
||||
});
|
||||
});
|
||||
|
||||
it ('lines_colors.obj', function (done) {
|
||||
ImportObjFile ('lines_colors.obj', function (model) {
|
||||
assert.ok (OV.CheckModel (model));
|
||||
assert.deepStrictEqual (ModelToObject (model), {
|
||||
name : '',
|
||||
materials : [
|
||||
{ name : 'Red' },
|
||||
{ name : 'Green' },
|
||||
{ name : 'Blue' }
|
||||
],
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0],
|
||||
mat : 0
|
||||
},
|
||||
{
|
||||
vertices : [1, 1, 0, 0, 1, 0],
|
||||
mat : 0
|
||||
},
|
||||
{
|
||||
vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1],
|
||||
mat : 1
|
||||
},
|
||||
{
|
||||
vertices : [0, 0, 0, 0, 0, 1],
|
||||
mat : 2
|
||||
}
|
||||
],
|
||||
triangles : []
|
||||
}
|
||||
]
|
||||
});
|
||||
done ();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@ -18,6 +18,7 @@ describe ('Off Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -44,6 +45,7 @@ describe ('Off Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -76,6 +78,7 @@ describe ('Off Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -108,6 +111,7 @@ describe ('Off Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -138,6 +142,7 @@ describe ('Off Importer', function () {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 12,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0, 0, 0],
|
||||
@ -162,6 +167,7 @@ describe ('Off Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -195,6 +201,7 @@ describe ('Off Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -229,6 +236,7 @@ describe ('Off Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -263,6 +271,7 @@ describe ('Off Importer', function () {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
|
||||
@ -18,6 +18,7 @@ describe ('Ply Importer', function() {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -44,6 +45,7 @@ describe ('Ply Importer', function() {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -76,6 +78,7 @@ describe ('Ply Importer', function() {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -108,6 +111,7 @@ describe ('Ply Importer', function() {
|
||||
meshes : [
|
||||
{
|
||||
name : '',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -138,6 +142,7 @@ describe ('Ply Importer', function() {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 12,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0, 0, 0],
|
||||
@ -165,6 +170,7 @@ describe ('Ply Importer', function() {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 12,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0, 0, 0],
|
||||
@ -192,6 +198,7 @@ describe ('Ply Importer', function() {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 12,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0, 0, 0],
|
||||
@ -222,6 +229,7 @@ describe ('Ply Importer', function() {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 12,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0, 0, 0],
|
||||
|
||||
@ -18,6 +18,7 @@ describe ('Stl Importer', function() {
|
||||
meshes : [
|
||||
{
|
||||
name : 'MeshName',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -44,6 +45,7 @@ describe ('Stl Importer', function() {
|
||||
meshes : [
|
||||
{
|
||||
name : 'MeshName',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -70,6 +72,7 @@ describe ('Stl Importer', function() {
|
||||
meshes : [
|
||||
{
|
||||
name : 'MeshName',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -96,6 +99,7 @@ describe ('Stl Importer', function() {
|
||||
meshes : [
|
||||
{
|
||||
name : 'MeshName',
|
||||
lines : [],
|
||||
triangles : [
|
||||
{
|
||||
vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0],
|
||||
@ -132,6 +136,7 @@ describe ('Stl Importer', function() {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 572,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 572,
|
||||
boundingBox : {
|
||||
min : [0, -1.10792799192095, 0],
|
||||
@ -159,6 +164,7 @@ describe ('Stl Importer', function() {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 728,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 728,
|
||||
boundingBox : {
|
||||
min : [0, -1.1079280376434326, 0],
|
||||
@ -187,6 +193,7 @@ describe ('Stl Importer', function() {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 12,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0, 0, 0],
|
||||
@ -214,6 +221,7 @@ describe ('Stl Importer', function() {
|
||||
vertexColorCount : 0,
|
||||
normalCount : 12,
|
||||
uvCount : 0,
|
||||
lineCount : 0,
|
||||
triangleCount : 12,
|
||||
boundingBox : {
|
||||
min : [0, 0, 0],
|
||||
|
||||
@ -52,6 +52,16 @@ describe ('Mesh', function() {
|
||||
assert.strictEqual (uv.y, 2.0);
|
||||
});
|
||||
|
||||
it ('Add Line', function () {
|
||||
var mesh = new OV.Mesh ();
|
||||
var index = mesh.AddLine (new OV.Line ([0, 1]));
|
||||
assert.strictEqual (index, 0);
|
||||
assert.strictEqual (mesh.LineCount (), 1);
|
||||
var line = mesh.GetLine (index);
|
||||
assert.strictEqual (line.vertices[0], 0);
|
||||
assert.strictEqual (line.vertices[1], 1);
|
||||
});
|
||||
|
||||
it ('Add Triangle', function () {
|
||||
var mesh = new OV.Mesh ();
|
||||
var triangle = new OV.Triangle (1, 2, 3);
|
||||
|
||||
@ -41,6 +41,9 @@ describe ('Model', function () {
|
||||
mesh.AddNormal (new OV.Coord3D (0.0, 0.0, 0.0));
|
||||
mesh.AddNormal (new OV.Coord3D (0.0, 0.0, 0.0));
|
||||
mesh.AddTextureUV (new OV.Coord2D (0.0, 0.0));
|
||||
mesh.AddLine (new OV.Line ([0, 1]));
|
||||
mesh.AddLine (new OV.Line ([1, 2]));
|
||||
mesh.AddLine (new OV.Line ([2, 0]));
|
||||
mesh.AddTriangle (new OV.Triangle (0, 1, 2));
|
||||
mesh.AddTriangle (new OV.Triangle (0, 1, 2));
|
||||
mesh.AddTriangle (new OV.Triangle (0, 1, 2));
|
||||
@ -49,6 +52,7 @@ describe ('Model', function () {
|
||||
assert.strictEqual (model.VertexCount (), 3);
|
||||
assert.strictEqual (model.NormalCount (), 2);
|
||||
assert.strictEqual (model.TextureUVCount (), 1);
|
||||
assert.strictEqual (model.LineCount (), 3);
|
||||
assert.strictEqual (model.TriangleCount (), 4);
|
||||
});
|
||||
|
||||
@ -86,6 +90,27 @@ describe ('Model', function () {
|
||||
});
|
||||
|
||||
describe ('Model Finalization', function () {
|
||||
it ('Create Default Material', function () {
|
||||
var mesh = new OV.Mesh ();
|
||||
var v0 = mesh.AddVertex (new OV.Coord3D (0.0, 0.0, 0.0));
|
||||
var v1 = mesh.AddVertex (new OV.Coord3D (1.0, 0.0, 0.0));
|
||||
var v2 = mesh.AddVertex (new OV.Coord3D (1.0, 1.0, 0.0));
|
||||
var v3 = mesh.AddVertex (new OV.Coord3D (1.0, 1.0, 0.0));
|
||||
mesh.AddLine (new OV.Line ([v0, v1]));
|
||||
mesh.AddLine (new OV.Line ([v1, v2]));
|
||||
mesh.AddTriangle (new OV.Triangle (v0, v1, v2));
|
||||
mesh.AddTriangle (new OV.Triangle (v0, v2, v3));
|
||||
var model = new OV.Model ();
|
||||
model.AddMesh (mesh);
|
||||
OV.FinalizeModel (model, {
|
||||
defaultLineMaterialColor : new OV.RGBColor (1, 2, 3),
|
||||
defaultMaterialColor : new OV.RGBColor (4, 5, 6)
|
||||
});
|
||||
assert.strictEqual (model.MaterialCount (), 2);
|
||||
assert.deepStrictEqual (model.GetMaterial (0).color, new OV.RGBColor (1, 2, 3));
|
||||
assert.deepStrictEqual (model.GetMaterial (1).color, new OV.RGBColor (4, 5, 6));
|
||||
});
|
||||
|
||||
it ('Calculate Normal', function () {
|
||||
var mesh = new OV.Mesh ();
|
||||
var v0 = mesh.AddVertex (new OV.Coord3D (0.0, 0.0, 0.0));
|
||||
|
||||
@ -16,6 +16,7 @@ describe ('Parameter List', function () {
|
||||
);
|
||||
let background = new OV.RGBAColor (4, 5, 6, 7);
|
||||
let color = new OV.RGBColor (1, 2, 3);
|
||||
let color2 = new OV.RGBColor (4, 5, 6);
|
||||
{
|
||||
let urlParams = OV.CreateUrlBuilder ().AddModelUrls (modelUrls).GetParameterList ();
|
||||
assert.strictEqual (urlParams, 'model=a.txt,b.txt');
|
||||
@ -36,6 +37,10 @@ describe ('Parameter List', function () {
|
||||
let urlParams = OV.CreateUrlBuilder ().AddModelUrls (modelUrls).AddCamera (camera).AddBackgroundColor (background).AddDefaultColor (color).GetParameterList ();
|
||||
assert.strictEqual (urlParams, 'model=a.txt,b.txt$camera=1.00000,1.00000,1.00000,0.00000,0.00000,0.00000,0.00000,0.00000,1.00000,45.00000$backgroundcolor=4,5,6,7$defaultcolor=1,2,3');
|
||||
}
|
||||
{
|
||||
let urlParams = OV.CreateUrlBuilder ().AddModelUrls (modelUrls).AddCamera (camera).AddBackgroundColor (background).AddDefaultColor (color).AddDefaultLineColor (color2).GetParameterList ();
|
||||
assert.strictEqual (urlParams, 'model=a.txt,b.txt$camera=1.00000,1.00000,1.00000,0.00000,0.00000,0.00000,0.00000,0.00000,1.00000,45.00000$backgroundcolor=4,5,6,7$defaultcolor=1,2,3$defaultlinecolor=4,5,6');
|
||||
}
|
||||
{
|
||||
let urlParams = OV.CreateUrlBuilder ().AddEdgeSettings (new EdgeSettings (
|
||||
true,
|
||||
|
||||
@ -11,6 +11,9 @@ export function ImportFile (importer, folder, fileName, onReady)
|
||||
return fileContent;
|
||||
});
|
||||
importer.Import (fileName, extension, content, {
|
||||
getDefaultLineMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
getDefaultMaterialColor () {
|
||||
return new OV.RGBColor (0, 0, 0);
|
||||
},
|
||||
|
||||
@ -55,7 +55,7 @@ export function ModelToObject (model)
|
||||
meshes : []
|
||||
};
|
||||
|
||||
var i, j;
|
||||
var i, j, k;
|
||||
|
||||
var material;
|
||||
for (i = 0; i < model.MaterialCount (); i++) {
|
||||
@ -65,13 +65,29 @@ export function ModelToObject (model)
|
||||
});
|
||||
}
|
||||
|
||||
var mesh, triangle, meshObj, triangleObj;
|
||||
var mesh, line, triangle, meshObj, lineObj, triangleObj;
|
||||
for (i = 0; i < model.MeshCount (); i++) {
|
||||
mesh = model.GetMesh (i);
|
||||
meshObj = {
|
||||
name : mesh.GetName (),
|
||||
lines : [],
|
||||
triangles : []
|
||||
};
|
||||
for (j = 0; j < mesh.LineCount (); j++) {
|
||||
line = mesh.GetLine (j);
|
||||
lineObj = {
|
||||
mat : line.mat,
|
||||
vertices : []
|
||||
};
|
||||
for (k = 0; k < line.vertices.length; k++) {
|
||||
lineObj.vertices.push (
|
||||
mesh.GetVertex (line.vertices[k]).x,
|
||||
mesh.GetVertex (line.vertices[k]).y,
|
||||
mesh.GetVertex (line.vertices[k]).z
|
||||
);
|
||||
}
|
||||
meshObj.lines.push (lineObj);
|
||||
}
|
||||
for (j = 0; j < mesh.TriangleCount (); j++) {
|
||||
triangle = mesh.GetTriangle (j);
|
||||
triangleObj = {
|
||||
@ -146,6 +162,7 @@ export function ModelToObjectSimple (model)
|
||||
vertexColorCount : mesh.VertexColorCount (),
|
||||
normalCount : mesh.NormalCount (),
|
||||
uvCount : mesh.TextureUVCount (),
|
||||
lineCount : mesh.LineSegmentCount (),
|
||||
triangleCount : mesh.TriangleCount (),
|
||||
boundingBox : {
|
||||
min : [boundingBox.min.x, boundingBox.min.y, boundingBox.min.z],
|
||||
|
||||
Loading…
Reference in New Issue
Block a user