Przeglądaj źródła

Catch errors when adding plugins

master
Palash Bansal 1 rok temu
rodzic
commit
95ec6bc792
No account linked to committer's email address

+ 5
- 5
package.json Wyświetl plik

{ {
"name": "threepipe", "name": "threepipe",
"version": "0.0.34",
"version": "0.0.35-dev",
"description": "A 3D viewer framework built on top of three.js in TypeScript with a focus on quality rendering, modularity and extensibility.", "description": "A 3D viewer framework built on top of three.js in TypeScript with a focus on quality rendering, modularity and extensibility.",
"main": "dist/index.js", "main": "dist/index.js",
"module": "dist/index.mjs", "module": "dist/index.mjs",
"eslint-plugin-html": "^7.1.0", "eslint-plugin-html": "^7.1.0",
"eslint-plugin-import": "^2.27.5", "eslint-plugin-import": "^2.27.5",
"local-web-server": "^5.3.0", "local-web-server": "^5.3.0",
"popmotion": "^11.0.5",
"rimraf": "^5.0.1", "rimraf": "^5.0.1",
"rollup-plugin-glsl": "^1.3.0", "rollup-plugin-glsl": "^1.3.0",
"rollup-plugin-license": "^3.0.1", "rollup-plugin-license": "^3.0.1",
"@types/wicg-file-system-access": "^2020.9.5", "@types/wicg-file-system-access": "^2020.9.5",
"stats.js": "^0.17.0", "stats.js": "^0.17.0",
"ts-browser-helpers": "^0.16.1", "ts-browser-helpers": "^0.16.1",
"uiconfig.js": "^0.1.2"
"uiconfig.js": "^0.1.2",
"popmotion": "^11.0.5"
}, },
"//": { "//": {
"dependencies": { "dependencies": {
"uiconfig.js": "^0.1.1",
"ts-browser-helpers": "^0.16.0",
"uiconfig.js": "^0.1.2",
"ts-browser-helpers": "^0.16.1",
"three": "https://github.com/repalash/three.js-modded/releases/download/v0.153.1006/package.tgz", "three": "https://github.com/repalash/three.js-modded/releases/download/v0.153.1006/package.tgz",
"three-f": "https://github.com/repalash/three.js-modded/archive/refs/tags/v0.153.1006.tar.gz", "three-f": "https://github.com/repalash/three.js-modded/archive/refs/tags/v0.153.1006.tar.gz",
"@types/three": "https://github.com/repalash/three-ts-types/releases/download/v0.153.1002/package.tgz", "@types/three": "https://github.com/repalash/three-ts-types/releases/download/v0.153.1002/package.tgz",

+ 13
- 7
src/assetmanager/import/Rhino3dmLoader2.ts Wyświetl plik

public static ForceLayerMaterials = false public static ForceLayerMaterials = false
public static ReplaceWithInstancedMesh = false public static ReplaceWithInstancedMesh = false
public static HideLineMesh = false public static HideLineMesh = false
public static HidePointMesh = false
public static LoadUserDataStrings = true
public static LoadUserDataWarnings = true


materials: Material[] = [] materials: Material[] = []


if (layer) obj.userData.rhinoLayer = layer if (layer) obj.userData.rhinoLayer = layer
obj.userData.rhino3dmRoot = ret.uuid obj.userData.rhino3dmRoot = ret.uuid


// console.log(obj.userData.attributes)
// instancing
if (!Rhino3dmLoader2.LoadUserDataStrings)
obj.userData.strings = []
if (!Rhino3dmLoader2.LoadUserDataWarnings)
delete obj.userData.warnings

this._hideLineMesh(obj) this._hideLineMesh(obj)
this._useInstancedMesh(obj) this._useInstancedMesh(obj)
this._useMaterialSource(obj, layer) this._useMaterialSource(obj, layer)
} }


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

+ 16
- 0
src/plugins/import/Rhino3dmLoadPlugin.ts Wyświetl plik

*/ */
@onChange(Rhino3dmLoadPlugin.prototype._refresh) @uiToggle() @onChange(Rhino3dmLoadPlugin.prototype._refresh) @uiToggle()
hideLineMesh = false hideLineMesh = false
/**
* Hide all points in the file
*/
@onChange(Rhino3dmLoadPlugin.prototype._refresh)
@uiToggle()
hidePointMesh = true

/**
* Remove strings from userData
*/
@onChange(Rhino3dmLoadPlugin.prototype._refresh)
@uiToggle()
loadUserDataStrings = true


protected _refresh() { protected _refresh() {
Rhino3dmLoader2.ImportMaterials = this.importMaterials Rhino3dmLoader2.ImportMaterials = this.importMaterials
Rhino3dmLoader2.ForceLayerMaterials = this.forceLayerMaterials Rhino3dmLoader2.ForceLayerMaterials = this.forceLayerMaterials
Rhino3dmLoader2.ReplaceWithInstancedMesh = this.replaceWithInstancedMesh Rhino3dmLoader2.ReplaceWithInstancedMesh = this.replaceWithInstancedMesh
Rhino3dmLoader2.HideLineMesh = this.hideLineMesh Rhino3dmLoader2.HideLineMesh = this.hideLineMesh
Rhino3dmLoader2.HidePointMesh = this.hidePointMesh
Rhino3dmLoader2.LoadUserDataStrings = this.loadUserDataStrings
Rhino3dmLoader2.LoadUserDataWarnings = false
} }


onAdded(viewer: ThreeViewer) { onAdded(viewer: ThreeViewer) {

+ 1
- 1
src/utils/GLStatsJS.ts Wyświetl plik

import Stats from 'stats.js' import Stats from 'stats.js'


export class GLStatsJS { export class GLStatsJS {
protected _stats: Stats = new Stats()
protected _stats: any = new Stats()
protected _container: HTMLElement protected _container: HTMLElement


constructor(container: HTMLElement) { constructor(container: HTMLElement) {

+ 36
- 17
src/viewer/ThreeViewer.ts Wyświetl plik

this._scene.renderCamera = cam this._scene.renderCamera = cam
if (cam.visible) this.renderManager.render(this._scene, this.renderManager.defaultRenderToScreen) if (cam.visible) this.renderManager.render(this._scene, this.renderManager.defaultRenderToScreen)
} catch (e) { } catch (e) {
this.console.error(e)
if (this.debug) throw e
this.console.error('ThreeViewer: Error while rendering frame. Enable debug mode to check the errors.')
if (this.debug) {
this.console.error(e)
throw e
}
// this.enabled = false // this.enabled = false
} }


*/ */
async addPlugin<T extends IViewerPlugin>(plugin: T | Class<T>, ...args: ConstructorParameters<Class<T>>): Promise<T> { async addPlugin<T extends IViewerPlugin>(plugin: T | Class<T>, ...args: ConstructorParameters<Class<T>>): Promise<T> {
const p = this._resolvePluginOrClass(plugin, ...args) const p = this._resolvePluginOrClass(plugin, ...args)
if (!p) {
throw new Error('ThreeViewer: Plugin is not defined')
}
const type = p.constructor.PluginType const type = p.constructor.PluginType
if (!p.constructor.PluginType) { if (!p.constructor.PluginType) {
this.console.error('PluginType is not defined for', p)
this.console.error('ThreeViewer: PluginType is not defined for', p)
return p return p
} }


} }


if (this.plugins[type]) { if (this.plugins[type]) {
this.console.error(`Plugin of type ${type} already exists, removing and disposing old plugin. This might break functionality, ensure only one plugin of a type is added`, this.plugins[type], p)
this.console.error(`ThreeViewer: Plugin of type ${type} already exists, removing and disposing old plugin. This might break functionality, ensure only one plugin of a type is added`, this.plugins[type], p)
await this.removePlugin(this.plugins[type]) await this.removePlugin(this.plugins[type])
} }
this.plugins[type] = p this.plugins[type] = p
const oldType = p.constructor.OldPluginType const oldType = p.constructor.OldPluginType
if (oldType && this.plugins[oldType]) this.console.error('Plugin type mismatch')
if (oldType && this.plugins[oldType]) this.console.error('ThreeViewer: Plugin type mismatch')
if (oldType) this.plugins[oldType] = p if (oldType) this.plugins[oldType] = p


await p.onAdded(this) await p.onAdded(this)
*/ */
addPluginSync<T extends IViewerPluginSync>(plugin: T|Class<T>, ...args: ConstructorParameters<Class<T>>): T { addPluginSync<T extends IViewerPluginSync>(plugin: T|Class<T>, ...args: ConstructorParameters<Class<T>>): T {
const p = this._resolvePluginOrClass(plugin, ...args) const p = this._resolvePluginOrClass(plugin, ...args)
if (!p) {
throw new Error('ThreeViewer: Plugin is not defined')
}
const type = p.constructor.PluginType const type = p.constructor.PluginType
if (!p.constructor.PluginType) { if (!p.constructor.PluginType) {
this.console.error('PluginType is not defined for', p)
this.console.error('ThreeViewer: PluginType is not defined for', p)
return p return p
} }
for (const d of p.dependencies || []) { for (const d of p.dependencies || []) {
} }


if (this.plugins[type]) { if (this.plugins[type]) {
this.console.error(`Plugin of type ${type} already exists, removing and disposing old plugin. This might break functionality, ensure only one plugin of a type is added`, this.plugins[type], p)
this.console.error(`ThreeViewer: Plugin of type ${type} already exists, removing and disposing old plugin. This might break functionality, ensure only one plugin of a type is added`, this.plugins[type], p)
this.removePluginSync(this.plugins[type]) this.removePluginSync(this.plugins[type])
} }
this.plugins[type] = p
const oldType = p.constructor.OldPluginType
if (oldType && this.plugins[oldType]) this.console.error('Plugin type mismatch')
if (oldType) this.plugins[oldType] = p
p.onAdded(this)
try {
this.plugins[type] = p
const oldType = p.constructor.OldPluginType
if (oldType && this.plugins[oldType]) this.console.error('ThreeViewer: Plugin type mismatch')
if (oldType) this.plugins[oldType] = p
p.onAdded(this)
} catch (e) {
this.console.error('ThreeViewer: Error adding plugin, check console for details', e)
delete this.plugins[type]
}
this._onPluginAdd(p) this._onPluginAdd(p)
return p return p
} }
} }


if (!meta?.__isLoadedResources) { if (!meta?.__isLoadedResources) {
this.console.error('meta in fromJSON is not available or is not loaded resources, call viewer.loadConfigResources first, or directly use viewer.importConfig')
this.console.error('ThreeViewer: meta in fromJSON is not available or is not loaded resources, call viewer.loadConfigResources first, or directly use viewer.importConfig')
return null return null
} }


this._scene.mainCamera = event.camera || undefined // event.camera should have been upgraded when added to the scene. this._scene.mainCamera = event.camera || undefined // event.camera should have been upgraded when added to the scene.
} }


private _resolvePluginOrClass<T extends IViewerPlugin>(plugin: T | Class<T>, ...args: ConstructorParameters<Class<T>>): T {
private _resolvePluginOrClass<T extends IViewerPlugin>(plugin: T | Class<T>, ...args: ConstructorParameters<Class<T>>): T|undefined {
let p: T let p: T
if ((plugin as Class<IViewerPlugin>).prototype) { if ((plugin as Class<IViewerPlugin>).prototype) {
const p1 = this.getPlugin(plugin as Class<T>) const p1 = this.getPlugin(plugin as Class<T>)
this.console.error(`Plugin of type ${p1.constructor.PluginType} already exists, no new plugin created`, p1) this.console.error(`Plugin of type ${p1.constructor.PluginType} already exists, no new plugin created`, p1)
return p1 return p1
} }
p = new (plugin as Class<T>)(...args)
try {
p = new (plugin as Class<T>)(...args)
} catch (e) {
this.console.error('ThreeViewer: Error creating plugin', e)
return undefined
}
} else p = plugin as T } else p = plugin as T
return p return p
} }
public async fitToView(selected?: Object3D, distanceMultiplier = 1.5, duration?: number, ease?: Easing|EasingFunctionType) { public async fitToView(selected?: Object3D, distanceMultiplier = 1.5, duration?: number, ease?: Easing|EasingFunctionType) {
const camViews = this.getPlugin<CameraViewPlugin>('CameraViews') const camViews = this.getPlugin<CameraViewPlugin>('CameraViews')
if (!camViews) { if (!camViews) {
this.console.error('CameraViewPlugin (CameraViews) is required for fitToView to work')
this.console.error('ThreeViewer: CameraViewPlugin (CameraViews) is required for fitToView to work')
return return
} }
await camViews?.animateToFitObject(selected, distanceMultiplier, duration, ease, {min: ((<OrbitControls3> this.scene.mainCamera.controls)?.minDistance ?? 0.5) + 0.5, max: 1000.0}) await camViews?.animateToFitObject(selected, distanceMultiplier, duration, ease, {min: ((<OrbitControls3> this.scene.mainCamera.controls)?.minDistance ?? 0.5) + 0.5, max: 1000.0})
* @deprecated - use {@link renderManager} instead * @deprecated - use {@link renderManager} instead
*/ */
get renderer(): ViewerRenderManager { get renderer(): ViewerRenderManager {
this.console.error('renderer is deprecated, use renderManager instead')
this.console.error('ThreeViewer: renderer is deprecated, use renderManager instead')
return this.renderManager return this.renderManager
} }



Ładowanie…
Anuluj
Zapisz