Quellcode durchsuchen

Optimise imports, minor changes

master
Palash Bansal vor 2 Jahren
Ursprung
Commit
62f72f22d7
Es ist kein Account mit der E-Mail-Adresse des Committers verbunden

+ 15
- 15
package-lock.json Datei anzeigen

@@ -1,15 +1,15 @@
{
"name": "threepipe",
"version": "0.0.6-dev",
"version": "0.0.7",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "threepipe",
"version": "0.0.6-dev",
"license": "MIT",
"version": "0.0.7",
"license": "Apache-2.0",
"dependencies": {
"@types/three": "https://github.com/repalash/three-ts-types/releases/download/v0.152.1010/package.tgz",
"@types/three": "https://github.com/repalash/three-ts-types/releases/download/v0.152.1011/package.tgz",
"@types/webxr": "^0.5.1",
"@types/wicg-file-system-access": "^2020.9.5",
"ts-browser-helpers": "^0.6.0"
@@ -37,7 +37,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.2009/package.tgz",
"three": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2010/package.tgz",
"tslib": "^2.5.0",
"tweakpane": "^3.1.9",
"tweakpane-image-plugin": "https://github.com/repalash/tweakpane-image-plugin/releases/download/v1.1.403/package.tgz",
@@ -670,9 +670,9 @@
"dev": true
},
"node_modules/@types/three": {
"version": "0.152.1010",
"resolved": "https://github.com/repalash/three-ts-types/releases/download/v0.152.1010/package.tgz",
"integrity": "sha512-Mnl6+lJhZUj2zLMqK7a5qrG8QLHHqHVQ8MJ7i5NzjGZ/ZJ//GqY6B24q7Z8F3ei8ASWQv0YteEfH5noc3Z2lMQ==",
"version": "0.152.1011",
"resolved": "https://github.com/repalash/three-ts-types/releases/download/v0.152.1011/package.tgz",
"integrity": "sha512-ZnWZWjxjNybypRf6aBaydSVPICNQ3HRdeHJXvhHWESFre1Whc7/WuF4VRd0EwfWPHMF8jSO4Y/TAQ0S+PG1hUA==",
"dependencies": {
"@tweenjs/tween.js": "~18.6.4",
"fflate": "~0.6.9",
@@ -9445,9 +9445,9 @@
}
},
"node_modules/three": {
"version": "0.152.2009",
"resolved": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2009/package.tgz",
"integrity": "sha512-qUqy+/uRzvW3F4xvyRCnnJVZ8yssgSYurrUCU1I3AJq7lz/p2CoWbdZYWXBXpNxR8+0Awx9S6Cy0Ah5Lq7g6Hw==",
"version": "0.152.2010",
"resolved": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2010/package.tgz",
"integrity": "sha512-STTCnJzxPLXkXCe41qSXx5G/bXWvkg22NjvBLCTwv8SpaP9m4HsTqNCbdwxu5cFjiPAtkYsBKnMqP4ows80urw==",
"dev": true,
"license": "MIT"
},
@@ -10802,8 +10802,8 @@
"dev": true
},
"@types/three": {
"version": "https://github.com/repalash/three-ts-types/releases/download/v0.152.1010/package.tgz",
"integrity": "sha512-Mnl6+lJhZUj2zLMqK7a5qrG8QLHHqHVQ8MJ7i5NzjGZ/ZJ//GqY6B24q7Z8F3ei8ASWQv0YteEfH5noc3Z2lMQ==",
"version": "https://github.com/repalash/three-ts-types/releases/download/v0.152.1011/package.tgz",
"integrity": "sha512-ZnWZWjxjNybypRf6aBaydSVPICNQ3HRdeHJXvhHWESFre1Whc7/WuF4VRd0EwfWPHMF8jSO4Y/TAQ0S+PG1hUA==",
"requires": {
"@tweenjs/tween.js": "~18.6.4",
"fflate": "~0.6.9",
@@ -17131,8 +17131,8 @@
}
},
"three": {
"version": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2009/package.tgz",
"integrity": "sha512-qUqy+/uRzvW3F4xvyRCnnJVZ8yssgSYurrUCU1I3AJq7lz/p2CoWbdZYWXBXpNxR8+0Awx9S6Cy0Ah5Lq7g6Hw==",
"version": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2010/package.tgz",
"integrity": "sha512-STTCnJzxPLXkXCe41qSXx5G/bXWvkg22NjvBLCTwv8SpaP9m4HsTqNCbdwxu5cFjiPAtkYsBKnMqP4ows80urw==",
"dev": true
},
"through": {

+ 8
- 8
package.json Datei anzeigen

@@ -1,6 +1,6 @@
{
"name": "threepipe",
"version": "0.0.6-dev",
"version": "0.0.7",
"description": "A 3D viewer framework built on top of three.js in TypeScript with a focus on quality rendering, modularity and extensibility.",
"main": "src/index.ts",
"module": "dist/index.mjs",
@@ -60,7 +60,7 @@
"canvas"
],
"author": "repalash <palash@shaders.app>",
"license": "MIT",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/repalash/threepipe/issues"
},
@@ -87,7 +87,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.2009/package.tgz",
"three": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2010/package.tgz",
"tslib": "^2.5.0",
"tweakpane": "^3.1.9",
"@tweakpane/core": "^1.1.8",
@@ -99,7 +99,7 @@
"tweakpane-image-plugin": "https://github.com/repalash/tweakpane-image-plugin/releases/download/v1.1.403/package.tgz"
},
"dependencies": {
"@types/three": "https://github.com/repalash/three-ts-types/releases/download/v0.152.1010/package.tgz",
"@types/three": "https://github.com/repalash/three-ts-types/releases/download/v0.152.1011/package.tgz",
"@types/webxr": "^0.5.1",
"@types/wicg-file-system-access": "^2020.9.5",
"ts-browser-helpers": "^0.6.0"
@@ -109,10 +109,10 @@
"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.2009/package.tgz",
"three-f": "https://github.com/repalash/three.js-modded/archive/refs/tags/v0.152.2009.tar.gz",
"@types/three": "https://github.com/repalash/three-ts-types/releases/download/v0.152.1010/package.tgz",
"@types/three-f": "https://github.com/repalash/three-ts-types/archive/refs/tags/v0.152.1010.tar.gz",
"three": "https://github.com/repalash/three.js-modded/releases/download/v0.152.2010/package.tgz",
"three-f": "https://github.com/repalash/three.js-modded/archive/refs/tags/v0.152.2010.tar.gz",
"@types/three": "https://github.com/repalash/three-ts-types/releases/download/v0.152.1011/package.tgz",
"@types/three-f": "https://github.com/repalash/three-ts-types/archive/refs/tags/v0.152.1011.tar.gz",
"@types/three-pkg": "https://gitpkg.now.sh/repalash/three-ts-types/types/three?modded_three",
"tweakpane-image-plugin": "git+ssh://github.com/repalash/tweakpane-image-plugin.git#52d5542047fd07d2e7225b5b67c9f7620366f2c7"
},

+ 7
- 1
src/assetmanager/AssetImporter.ts Datei anzeigen

@@ -256,7 +256,13 @@ export class AssetImporter extends EventDispatcher<IAssetImporterEvent, IAssetIm

res = await loader.loadAsync(path + (options.queryString ? (path.includes('?') ? '&' : '?') + options.queryString : ''), (e)=>{
if (onDownloadProgress) onDownloadProgress(e)
this.dispatchEvent({type: 'importFile', path, state:'downloading', progress: e.total > 0 ? e.loaded / e.total : 1})
this.dispatchEvent({
type: 'importFile', path,
state:'downloading',
loadedBytes: e.loaded || undefined,
totalBytes: e.total || undefined,
progress: e.total > 0 ? e.loaded / e.total : 1,
})
})
if (loader.transform) res = await loader.transform(res, options)


+ 15
- 7
src/assetmanager/export/GLTFExporter2.ts Datei anzeigen

@@ -4,6 +4,7 @@ import {GLTFWriter2} from './GLTFWriter2'
import {Object3D} from 'three'
import {ThreeViewer} from '../../viewer'
import {
glbEncryptionProcessor,
GLTFLightExtrasExtension,
GLTFMaterialExtrasExtension,
GLTFMaterialsAlphaMapExtension,
@@ -13,15 +14,16 @@ import {
GLTFObject3DExtrasExtension,
GLTFViewerConfigExtension,
} from '../gltf'
import {glbEncryptionProcessor} from '../gltf/gltfEncyptionHelpers'

export type GLTFExporter2Options = {
/**
* embed images in glb even when remote url is available, {@default false}
* embed images in glb even when remote url is available
* @default false
*/
embedUrlImages?: boolean,
/**
* Embed previews of images in glb, {@default false}
* Embed previews of images in glb
* @default false
*/
embedUrlImagePreviews?: boolean,
/**
@@ -38,19 +40,25 @@ export type GLTFExporter2Options = {
*/
externalImagesInExtras?: boolean,
/**
* see GLTFViewerExport->processViewer, {@default false}
* see GLTFViewerExport->processViewer
* @default false
*/
encodeUint16Rgbe?: boolean
/**
* Number of spaces to use when exporting to json, {@default 2}
* Number of spaces to use when exporting to json
* @default 2
*/
jsonSpaces?: number,
/**
* Encrypt the exported file in a GLB container using {@link encryptKey}, {@default false}. Works only for glb export.
* Encrypt the exported file in a GLB container using {@link encryptKey}
* @default false.
* Works only for glb export.
*/
encrypt?: boolean,
/**
* Encryption key, if not provided, will be prompted, {@default undefined}. Works only for glb export.
* Encryption key, if not provided, will be prompted
* @default undefined.
* Works only for glb export.
*/
encryptKey?: string|Uint8Array,


+ 13
- 13
src/assetmanager/gltf/gltfEncyptionHelpers.ts Datei anzeigen

@@ -33,36 +33,36 @@ export const glbEncryptionProcessor = async(gltf: ArrayBuffer|any, options: GLTF
}

export interface IGLBEncryptionPreparser extends GLTFPreparser{
key: string | ((encryption: any, json: any)=>string|Promise<string>)
key: string | ((encryption: any, json: any, path: string)=>string|Promise<string>)
}

/**
* Sample encryption preparser for {@link GLTFLoader2} that unwraps the glb container and decrypts the content. The encryption key can be provided in the file or set in this const is prompted from the user.
*/
export const glbEncryptionPreparser: IGLBEncryptionPreparser = {
key: (encryption: any, _: any) => {
return encryption.key || window && window.prompt && window.prompt('GLTFEncryption: Please enter the password/key for this model') || ''
key: (encryption: any, _: any, path: string) => {
return encryption.key || window && window.prompt && window.prompt('GLTFEncryption: Please enter the password/key for the model: ' + path) || ''
},
async process(dat: string | ArrayBuffer) {
if (typeof dat === 'string') return dat
async process(data: string | ArrayBuffer, path: string) {
if (typeof data === 'string') return data
const prefixBytes = 100
const prefix = new TextDecoder().decode(new Uint8Array(dat, 0, prefixBytes))
if (!prefix.includes('GLBWrapper')) return dat
const binaryExtension = new GLTFBinaryExtension(dat)
const prefix = new TextDecoder().decode(new Uint8Array(data, 0, prefixBytes))
if (!prefix.includes('GLBWrapper')) return data
const binaryExtension = new GLTFBinaryExtension(data)
const json = JSON.parse(binaryExtension.content || '{}')
let dat2 = binaryExtension.body || dat
let data2 = binaryExtension.body || data
const encryption = json.asset?.encryption
if (!encryption) return dat2
if (!encryption) return data2
const type = encryption.type
const version = encryption.version
if (type === 'aesgcm' && version === 1) {
const key = await getOrCall(this.key, encryption, json) || ''
const key = await getOrCall(this.key, encryption, json, path) || ''
try {
dat2 = (await aesGcmDecrypt(new Uint8Array(dat2), key)).buffer
data2 = (await aesGcmDecrypt(new Uint8Array(data2), key)).buffer
} catch (e) {
throw new ErrorEvent('decryption error')
}
}
return dat2
return data2
},
}

+ 18
- 16
src/assetmanager/import/GLTFLoader2.ts Datei anzeigen

@@ -1,19 +1,21 @@
import {GLTF, GLTFLoader, GLTFLoaderPlugin, GLTFParser} from 'three/examples/jsm/loaders/GLTFLoader.js'
import {LoadingManager, Object3D} from 'three'
import {AnyOptions, safeSetProperty} from 'ts-browser-helpers'
import {ThreeViewer} from '../../viewer/ThreeViewer'
import {generateUUID} from '../../three/utils/misc'
import {GLTFViewerConfigExtension} from '../gltf/GLTFViewerConfigExtension'
import {GLTFMaterialExtrasExtension} from '../gltf/GLTFMaterialExtrasExtension'
import {GLTFObject3DExtrasExtension} from '../gltf/GLTFObject3DExtrasExtension'
import {GLTFLightExtrasExtension} from '../gltf/GLTFLightExtrasExtension'
import {GLTFMaterialsBumpMapExtension} from '../gltf/GLTFMaterialsBumpMapExtension'
import {GLTFMaterialsLightMapExtension} from '../gltf/GLTFMaterialsLightMapExtension'
import {GLTFMaterialsDisplacementMapExtension} from '../gltf/GLTFMaterialsDisplacementMapExtension'
import {GLTFMaterialsAlphaMapExtension} from '../gltf/GLTFMaterialsAlphaMapExtension'
import {ThreeViewer} from '../../viewer'
import {generateUUID} from '../../three'
import {
glbEncryptionPreparser,
GLTFLightExtrasExtension,
GLTFMaterialExtrasExtension,
GLTFMaterialsAlphaMapExtension,
GLTFMaterialsBumpMapExtension,
GLTFMaterialsDisplacementMapExtension,
GLTFMaterialsLightMapExtension,
GLTFObject3DExtrasExtension,
GLTFViewerConfigExtension,
} from '../gltf'
import {RootSceneImportResult} from '../IAssetImporter'
import {ILoader} from '../IImporter'
import {glbEncryptionPreparser} from '../gltf'

export class GLTFLoader2 extends GLTFLoader implements ILoader<GLTF, Object3D|undefined> {
isGLTFLoader2 = true
@@ -36,15 +38,15 @@ export class GLTFLoader2 extends GLTFLoader implements ILoader<GLTF, Object3D|un
*/
preparsers: GLTFPreparser[] = []

async preparse(data: ArrayBuffer | string): Promise<ArrayBuffer | string> {
async preparse(data: ArrayBuffer | string, path: string): Promise<ArrayBuffer | string> {
for (const preparser of this.preparsers) {
data = await preparser.process(data)
data = await preparser.process(data, path)
}
return data
}

parse(data: ArrayBuffer | string, path: string, onLoad: (gltf: GLTF) => void, onError?: (event: ErrorEvent) => void) {
this.preparse.call(this, data)
parse(data: ArrayBuffer | string, path: string, onLoad: (gltf: GLTF) => void, onError?: (event: ErrorEvent) => void, url?: string) {
this.preparse.call(this, data, url || path)
.then((res: ArrayBuffer | string) => res ? super.parse(res, path, onLoad, onError) : onError && onError(new ErrorEvent('no data')))
.catch((e: any) => {
console.error(e)
@@ -130,6 +132,6 @@ export class GLTFLoader2 extends GLTFLoader implements ILoader<GLTF, Object3D|un
}

export interface GLTFPreparser{
process(dat: string | ArrayBuffer): Promise<string | ArrayBuffer>
process(data: string | ArrayBuffer, path: string): Promise<string | ArrayBuffer>
[key: string]: any
}

+ 3
- 5
src/core/IRenderer.ts Datei anzeigen

@@ -1,10 +1,8 @@
import {IDisposable, PartialRecord} from 'ts-browser-helpers'
import {Clock, Event, ShaderMaterial, Texture, Vector2, Vector4, WebGLRenderer, WebGLRenderTarget} from 'three'
import {CreateRenderTargetOptions, IRenderTarget} from '../rendering/RenderTarget'
import {IShaderPropertiesUpdater} from '../materials/MaterialExtension'
import {IPassID, IPipelinePass} from '../postprocessing/Pass'
import {EffectComposer2} from '../postprocessing/EffectComposer2'
import {RenderTargetManager} from '../rendering/RenderTargetManager'
import {CreateRenderTargetOptions, IRenderTarget, RenderTargetManager} from '../rendering'
import {IShaderPropertiesUpdater} from '../materials'
import {EffectComposer2, IPassID, IPipelinePass} from '../postprocessing'
import {IScene} from './IScene'
import {BlobExt} from '../assetmanager'


+ 2
- 2
src/core/IScene.ts Datei anzeigen

@@ -1,8 +1,8 @@
import {IObject3D, IObject3DEvent, IObject3DEventTypes, IObject3DUserData, IObjectSetDirtyOptions} from './IObject'
import {Color, Scene} from 'three'
import {IShaderPropertiesUpdater} from '../materials/MaterialExtension'
import {IShaderPropertiesUpdater} from '../materials'
import {ICamera} from './ICamera'
import {Box3B} from '../three/math/Box3B'
import {Box3B} from '../three'
import {ITexture} from './ITexture'

export interface AddObjectOptions {

+ 2
- 2
src/core/camera/PerspectiveCamera2.ts Datei anzeigen

@@ -4,9 +4,9 @@ import {onChange, onChange2, onChange3, serialize} from 'ts-browser-helpers'
import type {ICamera, ICameraEvent, ICameraUserData, TCameraControlsMode} from '../ICamera'
import {ICameraSetDirtyOptions} from '../ICamera'
import type {ICameraControls, TControlsCtor} from './ICameraControls'
import {OrbitControls3} from '../../three/controls/OrbitControls3'
import {OrbitControls3} from '../../three'
import {IObject3D} from '../IObject'
import {ThreeSerialization} from '../../utils/serialization'
import {ThreeSerialization} from '../../utils'
import {iCameraCommons} from '../object/iCameraCommons'

// todo: maybe change domElement to some wrapper/base class of viewer

+ 1
- 1
src/core/material/ExtendedShaderMaterial.ts Datei anzeigen

@@ -1,5 +1,5 @@
import {ShaderMaterial2} from './ShaderMaterial2'
import {getTexelDecoding2} from '../../three/utils/encoding'
import {getTexelDecoding2} from '../../three'
import {
BufferGeometry,
Camera,

+ 1
- 1
src/core/object/iObjectCommons.ts Datei anzeigen

@@ -2,7 +2,7 @@ import {Event, Mesh, Vector3} from 'three'
import {IMaterial} from '../IMaterial'
import {objectHasOwn} from 'ts-browser-helpers'
import {IObject3D, IObject3DEvent, IObjectProcessor, IObjectSetDirtyOptions} from '../IObject'
import {copyObject3DUserData} from '../../utils/serialization'
import {copyObject3DUserData} from '../../utils'
import {IGeometry, IGeometryEvent} from '../IGeometry'
import {Box3B} from '../../three'
import {makeIObject3DUiConfig} from './IObjectUi'

+ 2
- 3
src/plugins/base/PipelinePassPlugin.ts Datei anzeigen

@@ -1,8 +1,7 @@
import {IPassID, IPipelinePass} from '../../postprocessing'
import {ISerializedConfig, ThreeViewer} from '../../viewer'
import {AViewerPluginSync, ISerializedConfig, ThreeViewer} from '../../viewer'
import {AnyFunction, serialize} from 'ts-browser-helpers'
import {SerializationMetaType} from '../../utils/serialization'
import {AViewerPluginSync} from '../../viewer/AViewerPlugin'
import {SerializationMetaType} from '../../utils'

export abstract class PipelinePassPlugin<T extends IPipelinePass, TPassId extends IPassID, TEvent extends string, TViewer extends ThreeViewer=ThreeViewer> extends AViewerPluginSync<TEvent, TViewer> {
abstract passId: TPassId

+ 1
- 0
src/plugins/index.ts Datei anzeigen

@@ -5,6 +5,7 @@ export {PipelinePassPlugin} from './base/PipelinePassPlugin'
export {DepthBufferPlugin} from './pipeline/DepthBufferPlugin'
export {NormalBufferPlugin} from './pipeline/NormalBufferPlugin'
export type {DepthBufferPluginEventTypes, DepthBufferPluginPass, DepthBufferPluginTarget} from './pipeline/DepthBufferPlugin'
export type {NormalBufferPluginEventTypes, NormalBufferPluginPass, NormalBufferPluginTarget} from './pipeline/NormalBufferPlugin'

// ui
export {RenderTargetPreviewPlugin} from './ui/RenderTargetPreviewPlugin'

+ 2
- 1
src/plugins/interaction/DropzonePlugin.ts Datei anzeigen

@@ -1,5 +1,6 @@
import {AViewerPluginSync} from '../../viewer/AViewerPlugin'
import {type ThreeViewer} from '../../viewer/'
// noinspection ES6PreferShortImport
import {AViewerPluginSync} from '../../viewer/AViewerPlugin'
import {Dropzone} from '../../utils'
import {uiButton, uiConfig, uiFolderContainer, UiObjectConfig, uiToggle} from 'uiconfig.js'
import type {AddAssetOptions, ImportFilesOptions, ImportResult} from '../../assetmanager'

+ 5
- 2
src/viewer/ThreeViewer.ts Datei anzeigen

@@ -15,6 +15,8 @@ import {ViewerRenderManager} from './ViewerRenderManager'
import {
convertArrayBufferToStringsInMeta,
getEmptyMeta,
GLStatsJS,
IDialogWrapper,
jsonToBlob,
metaFromResources,
MetaImporter,
@@ -22,7 +24,8 @@ import {
SerializationMetaType,
SerializationResourcesType,
ThreeSerialization,
} from '../utils/serialization'
windowDialogWrapper,
} from '../utils'
import {
AssetManager,
AssetManagerOptions,
@@ -34,8 +37,8 @@ import {
ImportResult,
RootSceneImportResult,
} from '../assetmanager'
import {GLStatsJS, IDialogWrapper, windowDialogWrapper} from '../utils'
import {IViewerPlugin, IViewerPluginSync} from './IViewerPlugin'
// noinspection ES6PreferShortImport
import {DropzonePlugin, DropzonePluginOptions} from '../plugins/interaction/DropzonePlugin'
import {uiConfig, uiFolderContainer, UiObjectConfig} from 'uiconfig.js'
import {IRenderTarget} from '../rendering'

Laden…
Abbrechen
Speichern