소스 검색

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

master
Palash Bansal 2 년 전
부모
커밋
ae7f38bf54
No account linked to committer's email address
3개의 변경된 파일82개의 추가작업 그리고 10개의 파일을 삭제
  1. 3
    3
      package.json
  2. 41
    6
      src/assetmanager/import/Rhino3dmLoader2.ts
  3. 38
    1
      src/plugins/import/Rhino3dmLoadPlugin.ts

+ 3
- 3
package.json 파일 보기

"rollup-plugin-glsl": "^1.3.0", "rollup-plugin-glsl": "^1.3.0",
"rollup-plugin-postcss": "^4.0.2", "rollup-plugin-postcss": "^4.0.2",
"stats.js": "^0.17.0", "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", "tslib": "^2.5.0",
"typedoc": "^0.24.7", "typedoc": "^0.24.7",
"typescript": "^5.0.4", "typescript": "^5.0.4",
"dependencies": { "dependencies": {
"uiconfig.js": "^0.0.6", "uiconfig.js": "^0.0.6",
"ts-browser-helpers": "^0.8.0", "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": "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-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" "@types/three-pkg": "https://gitpkg.now.sh/repalash/three-ts-types/types/three?modded_three"

+ 41
- 6
src/assetmanager/import/Rhino3dmLoader2.ts 파일 보기

import {Rhino3dmLoader} from 'three/examples/jsm/loaders/3DMLoader.js' 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 { export class Rhino3dmLoader2 extends Rhino3dmLoader {
public static LIBRARY_PATH = 'https://cdn.jsdelivr.net/npm/rhino3dm@7.15.0/' public static LIBRARY_PATH = 'https://cdn.jsdelivr.net/npm/rhino3dm@7.15.0/'
this.setLibraryPath(Rhino3dmLoader2.LIBRARY_PATH) this.setLibraryPath(Rhino3dmLoader2.LIBRARY_PATH)
} }
public static ImportMaterials = true public static ImportMaterials = true
public static ForceLayerMaterials = false
public static ReplaceWithInstancedMesh = false
public static HideLineMesh = false


materials: Material[] = [] 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({ if (!Rhino3dmLoader2.ImportMaterials) return this.materials[0] || new MeshStandardMaterial({
color: new Color(1, 1, 1), color: new Color(1, 1, 1),
metalness: 0.8, metalness: 0.8,


// console.log(obj.userData.attributes) // console.log(obj.userData.attributes)
// instancing // instancing
this._hideLineMesh(obj)
this._useInstancedMesh(obj) this._useInstancedMesh(obj)
this._useMaterialSource(obj, layer) this._useMaterialSource(obj, layer)
}) })
private _useMaterialSource(obj: Object3D, layer: any) { private _useMaterialSource(obj: Object3D, layer: any) {
if (!Rhino3dmLoader2.ImportMaterials) return if (!Rhino3dmLoader2.ImportMaterials) return
const mesh = obj as Mesh 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 // https://developer.rhino3d.com/api/rhinoscript/object_methods/objectmaterialsource.htm
const materialSource = mesh.userData.attributes?.materialSource || mesh.userData.defAttributes?.materialSource const materialSource = mesh.userData.attributes?.materialSource || mesh.userData.defAttributes?.materialSource
const colorSource = mesh.userData.attributes?.colorSource || mesh.userData.defAttributes?.colorSource const colorSource = mesh.userData.attributes?.colorSource || mesh.userData.defAttributes?.colorSource
// const materialSource = mesh.userData.defAttributes?.materialSource // const materialSource = mesh.userData.defAttributes?.materialSource
// console.log(materialSource, mesh.userData.attributes, mesh.userData.defAttributes) // 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) { if (layer) {
mesh.material = this._compareMaterials(this._createMaterial({ mesh.material = this._compareMaterials(this._createMaterial({
diffuseColor: layer.color, diffuseColor: layer.color,
} }
} }


static ReplaceWithInstancedMesh = false
private _useInstancedMesh(obj: Object3D) { private _useInstancedMesh(obj: Object3D) {
if (!Rhino3dmLoader2.ReplaceWithInstancedMesh) return if (!Rhino3dmLoader2.ReplaceWithInstancedMesh) return
if (obj.children.length <= 0) return if (obj.children.length <= 0) return
} }
}) })
} }

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 파일 보기

import {onChange} from 'ts-browser-helpers'
import {Importer, Rhino3dmLoader2} from '../../assetmanager' import {Importer, Rhino3dmLoader2} from '../../assetmanager'
import {BaseImporterPlugin} from '../base/BaseImporterPlugin' 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. * Adds support for loading Rhino `.3dm`, `model/vnd.3dm`, `model/3dm` files and data uris.
* @category Plugins * @category Plugins
*/ */
export class Rhino3dmLoadPlugin extends BaseImporterPlugin {
@uiFolderContainer('Rhino 3dm Loader')
export class Rhino3dmLoadPlugin extends BaseImporterPlugin implements IUiConfigContainer {
public static readonly PluginType = 'Rhino3dmLoadPlugin' public static readonly PluginType = 'Rhino3dmLoadPlugin'
protected _importer = new Importer(Rhino3dmLoader2, ['3dm'], ['model/vnd.3dm', 'model/3dm'], true) 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
}

} }

Loading…
취소
저장