Browse Source

Export CopyShader, Shader in index.ts. Dispatch renderEnabled and renderDisabled event in ThreeViewer, add ThreeViewer.addPluginsSync. Other minor changes.

master
Palash Bansal 3 years ago
parent
commit
10dc20e9cd
No account linked to committer's email address

+ 6
- 6
package-lock.json View File

@@ -36,7 +36,7 @@
"rollup-plugin-license": "^3.0.1",
"rollup-plugin-postcss": "^4.0.2",
"stats.js": "^0.17.0",
"three": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2005/package.tgz",
"three": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2006/package.tgz",
"ts-browser-helpers": "^0.5.0",
"tslib": "^2.5.0",
"tweakpane": "^3.1.9",
@@ -9445,9 +9445,9 @@
}
},
"node_modules/three": {
"version": "0.152.2005",
"resolved": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2005/package.tgz",
"integrity": "sha512-2Bwo9rKQ++4Tufn5pdyyzcE+qxgUlAQGweFea+NTf4wN0T3kXNn0WUB2gzg1Qg191hAlNnhch7y5MhDnwdLltw==",
"version": "0.152.2006",
"resolved": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2006/package.tgz",
"integrity": "sha512-nlYUTwpYHQMRP7u68DL23MXFCD/2yZq5R372vJcFdjU3Jvum/9XlD+SLbR2ewUNYUj5Dl1WxEGgeWDkhXgHWwA==",
"dev": true,
"license": "MIT"
},
@@ -17132,8 +17132,8 @@
}
},
"three": {
"version": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2005/package.tgz",
"integrity": "sha512-2Bwo9rKQ++4Tufn5pdyyzcE+qxgUlAQGweFea+NTf4wN0T3kXNn0WUB2gzg1Qg191hAlNnhch7y5MhDnwdLltw==",
"version": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2006/package.tgz",
"integrity": "sha512-nlYUTwpYHQMRP7u68DL23MXFCD/2yZq5R372vJcFdjU3Jvum/9XlD+SLbR2ewUNYUj5Dl1WxEGgeWDkhXgHWwA==",
"dev": true
},
"through": {

+ 4
- 4
package.json View File

@@ -10,7 +10,7 @@
"scripts": {
"new:pack": "npm run prepare && clean-package && npm pack && clean-package restore",
"new:publish": "npm run prepare && clean-package && npm publish && clean-package restore",
"build": "rimraf dist ; NODE_ENV=production rollup -c",
"build": "rimraf dist && NODE_ENV=production rollup -c",
"dev": "rollup -c -w",
"build-examples": "tsc --project examples/tsconfig.build.json",
"dev-examples": "tsc --project examples/tsconfig.build.json -w",
@@ -88,7 +88,7 @@
"rollup-plugin-license": "^3.0.1",
"rollup-plugin-postcss": "^4.0.2",
"stats.js": "^0.17.0",
"three": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2005/package.tgz",
"three": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2006/package.tgz",
"ts-browser-helpers": "^0.5.0",
"tslib": "^2.5.0",
"tweakpane": "^3.1.9",
@@ -110,8 +110,8 @@
"uiconfig.js": "^0.0.4",
"ts-browser-helpers": "^0.5.0",
"uiconfig-tweakpane": "^0.0.3",
"three": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2005/package.tgz",
"three-f": "https://github.com/repalash/three.js-modded/archive/refs/tags/v0.152.2005.tar.gz",
"three": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2006/package.tgz",
"three-f": "https://github.com/repalash/three.js-modded/archive/refs/tags/v0.152.2006.tar.gz",
"@types/three": "https://github.com/repalash/three-ts-types/releases/download/v0.152.0004/package.tgz",
"@types/three-f": "https://github.com/repalash/three-ts-types/archive/refs/tags/v0.152.0004.tar.gz",
"@types/three-pkg": "https://gitpkg.now.sh/repalash/three-ts-types/types/three?modded_three",

+ 5
- 1
src/core/object/RootScene.ts View File

@@ -281,13 +281,17 @@ export class RootScene extends Scene<ISceneEvent, ISceneEventTypes> implements I
return this
}

/**
* Sets the backgroundColor property from a string, number or Color, and updates the scene.
* @param color
*/
setBackgroundColor(color: string | number | Color | null) {
this.backgroundColor = color ? new Color(color) : null
}

/**
* Mark the scene dirty, and force render in the next frame.
* @param options - set sceneUpdate to true to to mark that any object transformations have changed. It might trigger effects like frame fade depening on plugins.
* @param options - set `refreshScene` to true to mark that any object transformations have changed. It might trigger effects like frame fade depening on plugins.
* @returns {this}
*/
setDirty(options?: ISceneSetDirtyOptions): this {

+ 3
- 0
src/three/Threejs.ts View File

@@ -216,5 +216,8 @@ export {WebGLUtils} from 'three'

export * from 'three/src/constants.js'

export type {Shader} from 'three'

export * from 'three/examples/jsm/libs/fflate.module.js'

export {CopyShader} from 'three/examples/jsm/shaders/CopyShader.js'

+ 2
- 2
src/viewer/AViewerPlugin.ts View File

@@ -1,5 +1,5 @@
import {ISerializedConfig, ThreeViewer} from './ThreeViewer'
import {BaseEvent, EventDispatcher} from 'three'
import {Event, EventDispatcher} from 'three'
import {SerializationMetaType, ThreeSerialization} from '../utils'
import {IViewerPlugin, IViewerPluginAsync} from './IViewerPlugin'

@@ -7,7 +7,7 @@ import {IViewerPlugin, IViewerPluginAsync} from './IViewerPlugin'
* Base Class for Viewer Plugins
* @category Viewer
*/
export abstract class AViewerPlugin<T extends string, TViewer extends ThreeViewer = ThreeViewer, IsSync extends boolean = boolean> extends EventDispatcher<BaseEvent, T|'serialize'|'deserialize'> implements IViewerPlugin<TViewer, IsSync> {
export abstract class AViewerPlugin<T extends string, TViewer extends ThreeViewer = ThreeViewer, IsSync extends boolean = boolean> extends EventDispatcher<Event, T|'serialize'|'deserialize'> implements IViewerPlugin<TViewer, IsSync> {
declare ['constructor']: typeof AViewerPlugin
public static readonly PluginType: string = 'AViewerPlugin'
protected _dirty = false

+ 0
- 1
src/viewer/IViewerPlugin.ts View File

@@ -23,7 +23,6 @@ export interface IViewerPlugin<TViewer extends ThreeViewer = ThreeViewer, IsSync
// Called when this plug-in is removed from the viewer
onRemove(viewer: TViewer): IsSync extends false ? Promise<void> : void;


// the viewer will render the next frame if this is set to true
dirty?: boolean;


+ 38
- 16
src/viewer/ThreeViewer.ts View File

@@ -1,5 +1,5 @@
import {BaseEvent, Color, Event, EventDispatcher, LinearSRGBColorSpace, Object3D, Vector2} from 'three'
import {Class, createCanvasElement, serialize} from 'ts-browser-helpers'
import {Class, createCanvasElement, onChange, serialize} from 'ts-browser-helpers'
import {TViewerScreenShader} from '../postprocessing'
import {
AddObjectOptions,
@@ -38,7 +38,7 @@ import {DropzonePlugin, DropzonePluginOptions} from '../plugins/interaction/Drop
import {uiConfig, uiFolderContainer, UiObjectConfig} from 'uiconfig.js'

export type IViewerEvent = BaseEvent & {
type: 'update'|'preRender'|'postRender'|'preFrame'|'postFrame'|'dispose'|'addPlugin'
type: 'update'|'preRender'|'postRender'|'preFrame'|'postFrame'|'dispose'|'addPlugin'|'renderEnabled'|'renderDisabled'
}
export type IViewerEventTypes = IViewerEvent['type']
export interface ISerializedConfig {
@@ -132,7 +132,11 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
public static readonly ConfigTypeSlug = 'vjson'
uiConfig!: UiObjectConfig

static Console: IConsoleWrapper = console
static Console: IConsoleWrapper = {
log: console.log.bind(console),
warn: console.warn.bind(console),
error: console.error.bind(console),
}
static Dialog: IDialogWrapper = windowDialogWrapper

renderStats: GLStatsJS
@@ -172,10 +176,12 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
*/
enabled = true


/**
* Enable or disable all rendering, Animation loop including any frame/render events won't be fired when this is false.
*/
renderEnabled = true
@onChange(ThreeViewer.prototype._renderEnabledChanged)
renderEnabled = true

private _isRenderingFrame = false

@@ -190,12 +196,11 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
return this._scene
}


/**
* The ResizeObserver observing the canvas element. Add more elements to this observer to resize viewer on their size change.
* @type {ResizeObserver | undefined}
*/
readonly resizeObserver = window.ResizeObserver ? new window.ResizeObserver(_ => this.resize()) : undefined
readonly resizeObserver = window?.ResizeObserver ? new window.ResizeObserver(_ => this.resize()) : undefined

readonly debug: boolean
/**
@@ -260,7 +265,7 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
// render manager

if (options.isAntialiased !== undefined || options.useRgbm !== undefined || options.useGBufferDepth !== undefined) {
console.warn('isAntialiased, useRgbm and useGBufferDepth are deprecated, use msaa, rgbm and zPrepass instead.')
this.console.warn('isAntialiased, useRgbm and useGBufferDepth are deprecated, use msaa, rgbm and zPrepass instead.')
}
this.renderManager = new ViewerRenderManager({
canvas: this._canvas,
@@ -349,7 +354,7 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
* @deprecated - use {@link renderManager} instead
*/
get renderer(): ViewerRenderManager {
console.error('renderer is deprecated, use renderManager instead')
this.console.error('renderer is deprecated, use renderManager instead')
return this.renderManager
}

@@ -548,7 +553,7 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
}

/**
* Add a plugin with a type.
* Add a plugin to the viewer.
* @param plugin - The instance of the plugin to add or the class of the plugin to add.
* @param args - Arguments for the constructor of the plugin, in case a class is passed.
* @returns {Promise<T>} - The plugin added.
@@ -576,6 +581,11 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
return p
}

/**
* Add a plugin to the viewer(sync).
* @param plugin
* @param args
*/
addPluginSync<T extends IViewerPluginSync>(plugin: T|Class<T>, ...args: ConstructorParameters<Class<T>>): T {
const p = this._resolvePluginOrClass(plugin, ...args)
const type = p.constructor.PluginType
@@ -602,9 +612,9 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
for (const p of plugins) await this.addPlugin(p)
}

// async addPluginsSync(plugins: (IViewerPluginSync | Class<IViewerPluginSync>)[]): Promise<void> {
// for (const p of plugins) this.addPluginSync(p)
// }
async addPluginsSync(plugins: (IViewerPluginSync | Class<IViewerPluginSync>)[]): Promise<void> {
for (const p of plugins) this.addPluginSync(p)
}

/**
* Remove a plugin instance or a plugin class. Works similar to {@link ThreeViewer.addPlugin}
@@ -736,15 +746,15 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
* @param plugin
*/
async importPluginConfig(json: ISerializedConfig, plugin?: IViewerPlugin) {
// console.log('importing plugin preset', json, plugin)
// this.console.log('importing plugin preset', json, plugin)
const type = json.type
plugin = plugin || this.getPlugin(type)
if (!plugin) {
console.warn(`No plugin found for type ${type} to import config`)
this.console.warn(`No plugin found for type ${type} to import config`)
return undefined
}
if (!plugin.fromJSON) {
console.warn(`Plugin ${type} does not support importing presets`)
this.console.warn(`Plugin ${type} does not support importing presets`)
return undefined
}
const resources = json.resources || {}
@@ -901,7 +911,7 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
}

loadConfigResources = async(json: Partial<SerializationMetaType>, extraResources?: Partial<SerializationResourcesType>): Promise<any> => {
// console.log(json)
// this.console.log(json)
if (json.__isLoadedResources) return json
const meta = metaFromResources(json, this)
return await MetaImporter.ImportMeta(meta, extraResources)
@@ -933,6 +943,14 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
let p: T
if ((plugin as Class<IViewerPlugin>).prototype) p = new (plugin as Class<T>)(...args)
else p = plugin as T
if ((plugin as Class<IViewerPlugin>).prototype) {
const p1 = this.getPlugin(plugin as Class<T>)
if (p1) {
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)
} else p = plugin as T
return p
}

@@ -971,6 +989,10 @@ export class ThreeViewer extends EventDispatcher<IViewerEvent, IViewerEventTypes
}


private _renderEnabledChanged(): void {
this.dispatchEvent({type: this.renderEnabled ? 'renderEnabled' : 'renderDisabled'})
}

private readonly _defaultConfig: ISerializedViewerConfig = {
assetType: 'config',
type: this.type,

Loading…
Cancel
Save