Przeglądaj źródła

Add ForceLayerMaterials, HideLineMesh in Rhino3dmLoader2. Add importMaterials, forceLayerMaterials, replaceWithInstancedMesh, hideLineMesh in Rhino3dmLoadPlugin, three js minor version update

master
Palash Bansal 2 lat temu
rodzic
commit
ae7f38bf54
No account linked to committer's email address

+ 3
- 3
package.json Wyświetl plik

@@ -92,7 +92,7 @@
"rollup-plugin-glsl": "^1.3.0",
"rollup-plugin-postcss": "^4.0.2",
"stats.js": "^0.17.0",
"three": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2015/package.tgz",
"three": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2018/package.tgz",
"tslib": "^2.5.0",
"typedoc": "^0.24.7",
"typescript": "^5.0.4",
@@ -111,8 +111,8 @@
"dependencies": {
"uiconfig.js": "^0.0.6",
"ts-browser-helpers": "^0.8.0",
"three": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2015/package.tgz",
"three-f": "https://github.com/repalash/three.js-modded/archive/refs/tags/v0.152.2015.tar.gz",
"three": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2018/package.tgz",
"three-f": "https://github.com/repalash/three.js-modded/archive/refs/tags/v0.152.2018.tar.gz",
"@types/three": "https://github.com/repalash/three-ts-types/releases/download/v0.152.1017/package.tgz",
"@types/three-f": "https://github.com/repalash/three-ts-types/archive/refs/tags/v0.152.1017.tar.gz",
"@types/three-pkg": "https://gitpkg.now.sh/repalash/three-ts-types/types/three?modded_three"

+ 41
- 6
src/assetmanager/import/Rhino3dmLoader2.ts Wyświetl plik

@@ -1,5 +1,17 @@
import {Rhino3dmLoader} from 'three/examples/jsm/loaders/3DMLoader.js'
import {Color, DoubleSide, InstancedMesh, LoadingManager, Material, Mesh, MeshStandardMaterial, Object3D} from 'three'
import {
Color,
DoubleSide,
InstancedMesh,
Line,
LineSegments,
LoadingManager,
Material,
Mesh,
MeshStandardMaterial,
Object3D,
Points,
} from 'three'

export class Rhino3dmLoader2 extends Rhino3dmLoader {
public static LIBRARY_PATH = 'https://cdn.jsdelivr.net/npm/rhino3dm@7.15.0/'
@@ -9,10 +21,14 @@ export class Rhino3dmLoader2 extends Rhino3dmLoader {
this.setLibraryPath(Rhino3dmLoader2.LIBRARY_PATH)
}
public static ImportMaterials = true
public static ForceLayerMaterials = false
public static ReplaceWithInstancedMesh = false
public static HideLineMesh = false

materials: Material[] = []

protected _createMaterial(material: any): Material {
// eslint-disable-next-line @typescript-eslint/naming-convention
_createMaterial(material: any): Material {
if (!Rhino3dmLoader2.ImportMaterials) return this.materials[0] || new MeshStandardMaterial({
color: new Color(1, 1, 1),
metalness: 0.8,
@@ -43,6 +59,7 @@ export class Rhino3dmLoader2 extends Rhino3dmLoader {

// console.log(obj.userData.attributes)
// instancing
this._hideLineMesh(obj)
this._useInstancedMesh(obj)
this._useMaterialSource(obj, layer)
})
@@ -53,15 +70,17 @@ export class Rhino3dmLoader2 extends Rhino3dmLoader {
private _useMaterialSource(obj: Object3D, layer: any) {
if (!Rhino3dmLoader2.ImportMaterials) return
const mesh = obj as Mesh
if ((mesh.material as any)?.name === 'default') {
if ((mesh.material as any)?.name === 'default' || Rhino3dmLoader2.ForceLayerMaterials) {

// https://developer.rhino3d.com/api/rhinoscript/object_methods/objectmaterialsource.htm
const materialSource = mesh.userData.attributes?.materialSource || mesh.userData.defAttributes?.materialSource
const colorSource = mesh.userData.attributes?.colorSource || mesh.userData.defAttributes?.colorSource
// const materialSource = mesh.userData.defAttributes?.materialSource
// console.log(materialSource, mesh.userData.attributes, mesh.userData.defAttributes)
if (!materialSource && !colorSource) return
if (materialSource?.value === 0 || materialSource?.value === 1 && colorSource?.value === 0) { // material from layer
if (!Rhino3dmLoader2.ForceLayerMaterials && !materialSource && !colorSource) return
if (Rhino3dmLoader2.ForceLayerMaterials ||
(materialSource?.value === 0 || materialSource?.value === 1 && colorSource?.value === 0)
) { // material from layer
if (layer) {
mesh.material = this._compareMaterials(this._createMaterial({
diffuseColor: layer.color,
@@ -80,7 +99,6 @@ export class Rhino3dmLoader2 extends Rhino3dmLoader {
}
}

static ReplaceWithInstancedMesh = false
private _useInstancedMesh(obj: Object3D) {
if (!Rhino3dmLoader2.ReplaceWithInstancedMesh) return
if (obj.children.length <= 0) return
@@ -106,5 +124,22 @@ export class Rhino3dmLoader2 extends Rhino3dmLoader {
}
})
}

private _hideLineMesh(obj: Object3D) {
if (!Rhino3dmLoader2.HideLineMesh) return
if (obj.children.length <= 0) return
const toHide: any[] = []
obj.traverse((c) => {
if (c && (
(c as Line).isLine ||
(c as LineSegments).isLineSegments ||
(c as Points).isPoints
)) toHide.push(c)
})
toHide.forEach((c) => {
c.userData.visible_3dm = c.visible
c.visible = false
})
}
}


+ 38
- 1
src/plugins/import/Rhino3dmLoadPlugin.ts Wyświetl plik

@@ -1,11 +1,48 @@
import {onChange} from 'ts-browser-helpers'
import {Importer, Rhino3dmLoader2} from '../../assetmanager'
import {BaseImporterPlugin} from '../base/BaseImporterPlugin'
import {IUiConfigContainer, uiFolderContainer, UiObjectConfig, uiToggle} from 'uiconfig.js'

/**
* Adds support for loading Rhino `.3dm`, `model/vnd.3dm`, `model/3dm` files and data uris.
* @category Plugins
*/
export class Rhino3dmLoadPlugin extends BaseImporterPlugin {
@uiFolderContainer('Rhino 3dm Loader')
export class Rhino3dmLoadPlugin extends BaseImporterPlugin implements IUiConfigContainer {
public static readonly PluginType = 'Rhino3dmLoadPlugin'
protected _importer = new Importer(Rhino3dmLoader2, ['3dm'], ['model/vnd.3dm', 'model/3dm'], true)
uiConfig!: UiObjectConfig

/**
* Import materials from the file based on material source and color source. If false, a default material will be used
* Same as {@link Rhino3dmLoader2.ImportMaterials}
*/
@onChange(Rhino3dmLoadPlugin.prototype._refresh) @uiToggle()
importMaterials = Rhino3dmLoader2.ImportMaterials
/**
* Force layer materials even if material/color source is not from layer. Only works if {@link importMaterials} is true
* Same as {@link Rhino3dmLoader2.ForceLayerMaterials}
*/
@onChange(Rhino3dmLoadPlugin.prototype._refresh) @uiToggle()
forceLayerMaterials = Rhino3dmLoader2.ForceLayerMaterials
/**
* Replace meshes with instanced meshes if they have the same parent, geometry and material
* Same as {@link Rhino3dmLoader2.ReplaceWithInstancedMesh}
*/
@onChange(Rhino3dmLoadPlugin.prototype._refresh) @uiToggle()
replaceWithInstancedMesh = Rhino3dmLoader2.ReplaceWithInstancedMesh
/**
* Hide all lines, line segments and points in the file
* Same as {@link Rhino3dmLoader2.HideLineMesh}
*/
@onChange(Rhino3dmLoadPlugin.prototype._refresh) @uiToggle()
hideLineMesh = Rhino3dmLoader2.HideLineMesh

protected _refresh() {
Rhino3dmLoader2.ImportMaterials = this.importMaterials
Rhino3dmLoader2.ForceLayerMaterials = this.forceLayerMaterials
Rhino3dmLoader2.ReplaceWithInstancedMesh = this.replaceWithInstancedMesh
Rhino3dmLoader2.HideLineMesh = this.hideLineMesh
}

}

Ładowanie…
Anuluj
Zapisz