When importing STP format file, the model structure has no name and the material information is lost #220
This commit is contained in:
parent
84d0c78376
commit
97d9e560d1
@ -1,4 +1,4 @@
|
||||
importScripts ('https://cdn.jsdelivr.net/npm/occt-import-js@0.0.4/dist/occt-import-js.js');
|
||||
importScripts ('https://cdn.jsdelivr.net/npm/occt-import-js@0.0.5/dist/occt-import-js.js');
|
||||
|
||||
onmessage = async function (ev)
|
||||
{
|
||||
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
@ -43,7 +43,7 @@
|
||||
"rhino3dm": "7.14.0",
|
||||
"three": "0.138.3",
|
||||
"web-ifc": "0.0.33",
|
||||
"occt-import-js" : "0.0.4"
|
||||
"occt-import-js" : "0.0.5"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"env": {
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
import { Direction } from '../geometry/geometry.js';
|
||||
import { GetExternalLibPath } from '../io/externallibs.js';
|
||||
import { ColorFromFloatComponents, ColorToHexString } from '../model/color.js';
|
||||
import { PhongMaterial } from '../model/material.js';
|
||||
import { ConvertThreeGeometryToMesh } from '../threejs/threeutils.js';
|
||||
import { ImporterBase } from './importerbase.js';
|
||||
import { ColorToMaterialConverter } from './importerutils.js';
|
||||
|
||||
export class ImporterStp extends ImporterBase
|
||||
{
|
||||
@ -59,9 +62,32 @@ export class ImporterStp extends ImporterBase
|
||||
if (!stepContent.success) {
|
||||
return;
|
||||
}
|
||||
console.log (stepContent);
|
||||
let colorToMaterial = new ColorToMaterialConverter ((color) => {
|
||||
let material = new PhongMaterial ();
|
||||
material.name = ColorToHexString (color).toUpperCase ();
|
||||
material.color = color;
|
||||
return this.model.AddMaterial (material);
|
||||
});
|
||||
for (let occtMesh of stepContent.meshes) {
|
||||
let mesh = ConvertThreeGeometryToMesh (occtMesh, null);
|
||||
let materialIndex = null;
|
||||
if (occtMesh.color) {
|
||||
let color = ColorFromFloatComponents (occtMesh.color[0], occtMesh.color[1], occtMesh.color[2]);
|
||||
materialIndex = colorToMaterial.GetMaterialIndex (color);
|
||||
}
|
||||
let mesh = ConvertThreeGeometryToMesh (occtMesh, materialIndex);
|
||||
if (occtMesh.name) {
|
||||
mesh.SetName (occtMesh.name);
|
||||
}
|
||||
if (occtMesh.face_colors) {
|
||||
for (let faceColorGroup of occtMesh.face_colors) {
|
||||
let faceColor = ColorFromFloatComponents (faceColorGroup.color[0], faceColorGroup.color[1], faceColorGroup.color[2]);
|
||||
let faceMaterialIndex = colorToMaterial.GetMaterialIndex (faceColor);
|
||||
for (let i = faceColorGroup.first; i <= faceColorGroup.last; i++) {
|
||||
let triangle = mesh.GetTriangle (i);
|
||||
triangle.SetMaterial (faceMaterialIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.model.AddMeshToRootNode (mesh);
|
||||
}
|
||||
onFinish ();
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { IsLower } from '../geometry/geometry.js';
|
||||
import { ColorToHexString } from '../model/color.js';
|
||||
|
||||
export function NameFromLine (line, startIndex, commentChar)
|
||||
{
|
||||
@ -62,3 +63,24 @@ export function UpdateMaterialTransparency (material)
|
||||
material.transparent = true;
|
||||
}
|
||||
}
|
||||
|
||||
export class ColorToMaterialConverter
|
||||
{
|
||||
constructor (createMaterialFunc)
|
||||
{
|
||||
this.createMaterialFunc = createMaterialFunc;
|
||||
this.colorToMaterialIndex = new Map ();
|
||||
}
|
||||
|
||||
GetMaterialIndex (color)
|
||||
{
|
||||
let colorKey = ColorToHexString (color);
|
||||
if (this.colorToMaterialIndex.has (colorKey)) {
|
||||
return this.colorToMaterialIndex.get (colorKey);
|
||||
} else {
|
||||
let materialIndex = this.createMaterialFunc (color);
|
||||
this.colorToMaterialIndex.set (colorKey, materialIndex);
|
||||
return materialIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ import { ImporterStl } from './import/importerstl.js';
|
||||
import { ImporterStp } from './import/importerstp.js';
|
||||
import { ImporterThreeSvg } from './import/importersvg.js';
|
||||
import { ImporterThreeBase, ImporterThreeFbx, ImporterThreeDae, ImporterThreeWrl, ImporterThree3mf } from './import/importerthree.js';
|
||||
import { NameFromLine, ParametersFromLine, ReadLines, IsPowerOfTwo, NextPowerOfTwo, UpdateMaterialTransparency } from './import/importerutils.js';
|
||||
import { ColorToMaterialConverter, NameFromLine, ParametersFromLine, ReadLines, IsPowerOfTwo, NextPowerOfTwo, UpdateMaterialTransparency } from './import/importerutils.js';
|
||||
import { BinaryReader } from './io/binaryreader.js';
|
||||
import { BinaryWriter } from './io/binarywriter.js';
|
||||
import { ArrayBufferToUtf8String, ArrayBufferToAsciiString, AsciiStringToArrayBuffer, Utf8StringToArrayBuffer, Base64DataURIToArrayBuffer, GetFileExtensionFromMimeType, CreateObjectUrl, CreateObjectUrlWithMimeType, RevokeObjectUrl } from './io/bufferutils.js';
|
||||
@ -162,6 +162,7 @@ export {
|
||||
ImporterThreeDae,
|
||||
ImporterThreeWrl,
|
||||
ImporterThree3mf,
|
||||
ColorToMaterialConverter,
|
||||
NameFromLine,
|
||||
ParametersFromLine,
|
||||
ReadLines,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user