Преглед изворни кода

Catch errors when adding plugins

master
Palash Bansal пре 1 година
родитељ
комит
95ec6bc792
No account linked to committer's email address

+ 5
- 5
package.json Прегледај датотеку

@@ -1,6 +1,6 @@
{
"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.",
"main": "dist/index.js",
"module": "dist/index.mjs",
@@ -97,7 +97,6 @@
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-import": "^2.27.5",
"local-web-server": "^5.3.0",
"popmotion": "^11.0.5",
"rimraf": "^5.0.1",
"rollup-plugin-glsl": "^1.3.0",
"rollup-plugin-license": "^3.0.1",
@@ -117,12 +116,13 @@
"@types/wicg-file-system-access": "^2020.9.5",
"stats.js": "^0.17.0",
"ts-browser-helpers": "^0.16.1",
"uiconfig.js": "^0.1.2"
"uiconfig.js": "^0.1.2",
"popmotion": "^11.0.5"
},
"//": {
"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-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",

+ 13
- 7
src/assetmanager/import/Rhino3dmLoader2.ts Прегледај датотеку

@@ -24,6 +24,9 @@ export class Rhino3dmLoader2 extends Rhino3dmLoader {
public static ForceLayerMaterials = false
public static ReplaceWithInstancedMesh = false
public static HideLineMesh = false
public static HidePointMesh = false
public static LoadUserDataStrings = true
public static LoadUserDataWarnings = true

materials: Material[] = []

@@ -57,8 +60,11 @@ export class Rhino3dmLoader2 extends Rhino3dmLoader {
if (layer) obj.userData.rhinoLayer = layer
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._useInstancedMesh(obj)
this._useMaterialSource(obj, layer)
@@ -126,15 +132,15 @@ export class Rhino3dmLoader2 extends Rhino3dmLoader {
}

private _hideLineMesh(obj: Object3D) {
if (!Rhino3dmLoader2.HideLineMesh) return
if (!Rhino3dmLoader2.HideLineMesh && !Rhino3dmLoader2.HidePointMesh) 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)
Rhino3dmLoader2.HideLineMesh && ((c as Line).isLine || (c as LineSegments).isLineSegments))
||
Rhino3dmLoader2.HidePointMesh && (c as Points).isPoints
) toHide.push(c)
})
toHide.forEach((c) => {
c.userData.visible_3dm = c.visible

+ 16
- 0
src/plugins/import/Rhino3dmLoadPlugin.ts Прегледај датотеку

@@ -38,12 +38,28 @@ export class Rhino3dmLoadPlugin extends BaseImporterPlugin implements IUiConfigC
*/
@onChange(Rhino3dmLoadPlugin.prototype._refresh) @uiToggle()
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() {
Rhino3dmLoader2.ImportMaterials = this.importMaterials
Rhino3dmLoader2.ForceLayerMaterials = this.forceLayerMaterials
Rhino3dmLoader2.ReplaceWithInstancedMesh = this.replaceWithInstancedMesh
Rhino3dmLoader2.HideLineMesh = this.hideLineMesh
Rhino3dmLoader2.HidePointMesh = this.hidePointMesh
Rhino3dmLoader2.LoadUserDataStrings = this.loadUserDataStrings
Rhino3dmLoader2.LoadUserDataWarnings = false
}

onAdded(viewer: ThreeViewer) {

+ 1
- 1
src/utils/GLStatsJS.ts Прегледај датотеку

@@ -1,7 +1,7 @@
import Stats from 'stats.js'

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

constructor(container: HTMLElement) {

+ 36
- 17
src/viewer/ThreeViewer.ts Прегледај датотеку

@@ -682,8 +682,11 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
this._scene.renderCamera = cam
if (cam.visible) this.renderManager.render(this._scene, this.renderManager.defaultRenderToScreen)
} 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
}

@@ -746,9 +749,12 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
*/
async addPlugin<T extends IViewerPlugin>(plugin: T | Class<T>, ...args: ConstructorParameters<Class<T>>): Promise<T> {
const p = this._resolvePluginOrClass(plugin, ...args)
if (!p) {
throw new Error('ThreeViewer: Plugin is not defined')
}
const type = 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
}

@@ -757,12 +763,12 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
}

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])
}
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]) this.console.error('ThreeViewer: Plugin type mismatch')
if (oldType) this.plugins[oldType] = p

await p.onAdded(this)
@@ -777,9 +783,12 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
*/
addPluginSync<T extends IViewerPluginSync>(plugin: T|Class<T>, ...args: ConstructorParameters<Class<T>>): T {
const p = this._resolvePluginOrClass(plugin, ...args)
if (!p) {
throw new Error('ThreeViewer: Plugin is not defined')
}
const type = 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
}
for (const d of p.dependencies || []) {
@@ -787,14 +796,19 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
}

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.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)
return p
}
@@ -1168,7 +1182,7 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
}

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
}

@@ -1249,7 +1263,7 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
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
if ((plugin as Class<IViewerPlugin>).prototype) {
const p1 = this.getPlugin(plugin as Class<T>)
@@ -1257,7 +1271,12 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
this.console.error(`Plugin of type ${p1.constructor.PluginType} already exists, no new plugin created`, 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
return p
}
@@ -1304,7 +1323,7 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
public async fitToView(selected?: Object3D, distanceMultiplier = 1.5, duration?: number, ease?: Easing|EasingFunctionType) {
const camViews = this.getPlugin<CameraViewPlugin>('CameraViews')
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
}
await camViews?.animateToFitObject(selected, distanceMultiplier, duration, ease, {min: ((<OrbitControls3> this.scene.mainCamera.controls)?.minDistance ?? 0.5) + 0.5, max: 1000.0})
@@ -1384,7 +1403,7 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
* @deprecated - use {@link renderManager} instead
*/
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
}


Loading…
Откажи
Сачувај