ソースを参照

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

master
Palash Bansal 3年前
コミット
10dc20e9cd
コミッターのメールアドレスに関連付けられたアカウントが存在しません

+ 6
- 6
package-lock.json ファイルの表示

"rollup-plugin-license": "^3.0.1", "rollup-plugin-license": "^3.0.1",
"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.2005/package.tgz",
"three": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2006/package.tgz",
"ts-browser-helpers": "^0.5.0", "ts-browser-helpers": "^0.5.0",
"tslib": "^2.5.0", "tslib": "^2.5.0",
"tweakpane": "^3.1.9", "tweakpane": "^3.1.9",
} }
}, },
"node_modules/three": { "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, "dev": true,
"license": "MIT" "license": "MIT"
}, },
} }
}, },
"three": { "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 "dev": true
}, },
"through": { "through": {

+ 4
- 4
package.json ファイルの表示

"scripts": { "scripts": {
"new:pack": "npm run prepare && clean-package && npm pack && clean-package restore", "new:pack": "npm run prepare && clean-package && npm pack && clean-package restore",
"new:publish": "npm run prepare && clean-package && npm publish && 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", "dev": "rollup -c -w",
"build-examples": "tsc --project examples/tsconfig.build.json", "build-examples": "tsc --project examples/tsconfig.build.json",
"dev-examples": "tsc --project examples/tsconfig.build.json -w", "dev-examples": "tsc --project examples/tsconfig.build.json -w",
"rollup-plugin-license": "^3.0.1", "rollup-plugin-license": "^3.0.1",
"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.2005/package.tgz",
"three": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2006/package.tgz",
"ts-browser-helpers": "^0.5.0", "ts-browser-helpers": "^0.5.0",
"tslib": "^2.5.0", "tslib": "^2.5.0",
"tweakpane": "^3.1.9", "tweakpane": "^3.1.9",
"uiconfig.js": "^0.0.4", "uiconfig.js": "^0.0.4",
"ts-browser-helpers": "^0.5.0", "ts-browser-helpers": "^0.5.0",
"uiconfig-tweakpane": "^0.0.3", "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": "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-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", "@types/three-pkg": "https://gitpkg.now.sh/repalash/three-ts-types/types/three?modded_three",

+ 5
- 1
src/core/object/RootScene.ts ファイルの表示

return this return this
} }


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


/** /**
* Mark the scene dirty, and force render in the next frame. * 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} * @returns {this}
*/ */
setDirty(options?: ISceneSetDirtyOptions): this { setDirty(options?: ISceneSetDirtyOptions): this {

+ 3
- 0
src/three/Threejs.ts ファイルの表示



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


export type {Shader} from 'three'


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

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

+ 2
- 2
src/viewer/AViewerPlugin.ts ファイルの表示

import {ISerializedConfig, ThreeViewer} from './ThreeViewer' import {ISerializedConfig, ThreeViewer} from './ThreeViewer'
import {BaseEvent, EventDispatcher} from 'three'
import {Event, EventDispatcher} from 'three'
import {SerializationMetaType, ThreeSerialization} from '../utils' import {SerializationMetaType, ThreeSerialization} from '../utils'
import {IViewerPlugin, IViewerPluginAsync} from './IViewerPlugin' import {IViewerPlugin, IViewerPluginAsync} from './IViewerPlugin'


* Base Class for Viewer Plugins * Base Class for Viewer Plugins
* @category Viewer * @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 declare ['constructor']: typeof AViewerPlugin
public static readonly PluginType: string = 'AViewerPlugin' public static readonly PluginType: string = 'AViewerPlugin'
protected _dirty = false protected _dirty = false

+ 0
- 1
src/viewer/IViewerPlugin.ts ファイルの表示

// Called when this plug-in is removed from the viewer // Called when this plug-in is removed from the viewer
onRemove(viewer: TViewer): IsSync extends false ? Promise<void> : void; onRemove(viewer: TViewer): IsSync extends false ? Promise<void> : void;



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



+ 38
- 16
src/viewer/ThreeViewer.ts ファイルの表示

import {BaseEvent, Color, Event, EventDispatcher, LinearSRGBColorSpace, Object3D, Vector2} from 'three' 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 {TViewerScreenShader} from '../postprocessing'
import { import {
AddObjectOptions, AddObjectOptions,
import {uiConfig, uiFolderContainer, UiObjectConfig} from 'uiconfig.js' import {uiConfig, uiFolderContainer, UiObjectConfig} from 'uiconfig.js'


export type IViewerEvent = BaseEvent & { 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 type IViewerEventTypes = IViewerEvent['type']
export interface ISerializedConfig { export interface ISerializedConfig {
public static readonly ConfigTypeSlug = 'vjson' public static readonly ConfigTypeSlug = 'vjson'
uiConfig!: UiObjectConfig 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 static Dialog: IDialogWrapper = windowDialogWrapper


renderStats: GLStatsJS renderStats: GLStatsJS
*/ */
enabled = true enabled = true



/** /**
* Enable or disable all rendering, Animation loop including any frame/render events won't be fired when this is false. * 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 private _isRenderingFrame = false


return this._scene return this._scene
} }



/** /**
* The ResizeObserver observing the canvas element. Add more elements to this observer to resize viewer on their size change. * The ResizeObserver observing the canvas element. Add more elements to this observer to resize viewer on their size change.
* @type {ResizeObserver | undefined} * @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 readonly debug: boolean
/** /**
// render manager // render manager


if (options.isAntialiased !== undefined || options.useRgbm !== undefined || options.useGBufferDepth !== undefined) { 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({ this.renderManager = new ViewerRenderManager({
canvas: this._canvas, canvas: this._canvas,
* @deprecated - use {@link renderManager} instead * @deprecated - use {@link renderManager} instead
*/ */
get renderer(): ViewerRenderManager { get renderer(): ViewerRenderManager {
console.error('renderer is deprecated, use renderManager instead')
this.console.error('renderer is deprecated, use renderManager instead')
return this.renderManager return this.renderManager
} }


} }


/** /**
* 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 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. * @param args - Arguments for the constructor of the plugin, in case a class is passed.
* @returns {Promise<T>} - The plugin added. * @returns {Promise<T>} - The plugin added.
return p 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 { 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)
const type = p.constructor.PluginType const type = p.constructor.PluginType
for (const p of plugins) await this.addPlugin(p) 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} * Remove a plugin instance or a plugin class. Works similar to {@link ThreeViewer.addPlugin}
* @param plugin * @param plugin
*/ */
async importPluginConfig(json: ISerializedConfig, plugin?: IViewerPlugin) { 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 const type = json.type
plugin = plugin || this.getPlugin(type) plugin = plugin || this.getPlugin(type)
if (!plugin) { 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 return undefined
} }
if (!plugin.fromJSON) { if (!plugin.fromJSON) {
console.warn(`Plugin ${type} does not support importing presets`)
this.console.warn(`Plugin ${type} does not support importing presets`)
return undefined return undefined
} }
const resources = json.resources || {} const resources = json.resources || {}
} }


loadConfigResources = async(json: Partial<SerializationMetaType>, extraResources?: Partial<SerializationResourcesType>): Promise<any> => { loadConfigResources = async(json: Partial<SerializationMetaType>, extraResources?: Partial<SerializationResourcesType>): Promise<any> => {
// console.log(json)
// this.console.log(json)
if (json.__isLoadedResources) return json if (json.__isLoadedResources) return json
const meta = metaFromResources(json, this) const meta = metaFromResources(json, this)
return await MetaImporter.ImportMeta(meta, extraResources) return await MetaImporter.ImportMeta(meta, extraResources)
let p: T let p: T
if ((plugin as Class<IViewerPlugin>).prototype) p = new (plugin as Class<T>)(...args) if ((plugin as Class<IViewerPlugin>).prototype) p = new (plugin as Class<T>)(...args)
else p = plugin as T 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 return p
} }


} }




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

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

読み込み中…
キャンセル
保存