@xviewer.js/core 1.0.0-alpha.13 → 1.0.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +168 -43
- package/dist/main.js.map +1 -1
- package/dist/module.js +169 -45
- package/dist/module.js.map +1 -1
- package/package.json +1 -5
- package/types/PropertyManager.d.ts +14 -4
- package/types/Viewer.d.ts +0 -1
- package/types/base/getClassInstance.d.ts +1 -0
- package/types/base/index.d.ts +1 -0
package/dist/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Mesh, EquirectangularReflectionMapping, FileLoader, TextureLoader, MathUtils, Vector3, Quaternion, Raycaster, Vector2, Spherical, Object3D, BoxGeometry, SphereGeometry, PlaneGeometry, HalfFloatType, FloatType, UnsignedByteType, OrthographicCamera, BufferGeometry, Float32BufferAttribute, WebGLRenderTarget, ClampToEdgeWrapping, NearestFilter, LinearFilter, LinearMipMapLinearFilter, SRGBColorSpace, WebGLCubeRenderTarget, DataTexture, RGBAFormat, UVMapping, Scene, PerspectiveCamera, WebGLRenderer, PCFSoftShadowMap, LoadingManager
|
|
1
|
+
import { Mesh, EquirectangularReflectionMapping, FileLoader, TextureLoader, MathUtils, Vector3, Quaternion, Raycaster, Vector2, Spherical, Object3D, BoxGeometry, SphereGeometry, PlaneGeometry, HalfFloatType, FloatType, UnsignedByteType, OrthographicCamera, BufferGeometry, Float32BufferAttribute, WebGLRenderTarget, ClampToEdgeWrapping, NearestFilter, LinearFilter, LinearMipMapLinearFilter, SRGBColorSpace, WebGLCubeRenderTarget, DataTexture, RGBAFormat, UVMapping, Scene, LinearToneMapping, PerspectiveCamera, WebGLRenderer, PCFSoftShadowMap, LoadingManager } from 'three';
|
|
2
2
|
import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js';
|
|
3
3
|
import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js';
|
|
4
4
|
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
|
@@ -135,6 +135,10 @@ function mixin(derivedCtor, baseCtors) {
|
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
function getClassInstance(constructor, args = []) {
|
|
139
|
+
return typeof constructor === "function" ? new constructor(...args) : constructor;
|
|
140
|
+
}
|
|
141
|
+
|
|
138
142
|
/**
|
|
139
143
|
* The Ease class provides a collection of easing functions for use with tween.js.
|
|
140
144
|
*/ var Easing = {
|
|
@@ -1184,18 +1188,36 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
1184
1188
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1185
1189
|
};
|
|
1186
1190
|
|
|
1191
|
+
class ClassProperties {
|
|
1192
|
+
property(propertyKey, options = {}) {
|
|
1193
|
+
this._properties[propertyKey] = options;
|
|
1194
|
+
return this;
|
|
1195
|
+
}
|
|
1196
|
+
applyProperties(target) {
|
|
1197
|
+
Object.assign(target, this._properties);
|
|
1198
|
+
return target;
|
|
1199
|
+
}
|
|
1200
|
+
constructor(clsName){
|
|
1201
|
+
this.clsName = clsName;
|
|
1202
|
+
this._properties = Object.create(null);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1187
1205
|
class PropertyManager {
|
|
1188
|
-
static
|
|
1189
|
-
return PropertyManager.
|
|
1206
|
+
static _hasProperties(constructor) {
|
|
1207
|
+
return PropertyManager._propertyMap.has(constructor);
|
|
1190
1208
|
}
|
|
1191
|
-
static
|
|
1192
|
-
|
|
1209
|
+
static _getProperties(constructor, autoAdd = true) {
|
|
1210
|
+
let props = PropertyManager._propertyMap.get(constructor);
|
|
1211
|
+
if (props === undefined && autoAdd) {
|
|
1212
|
+
props = Object.create(null);
|
|
1213
|
+
PropertyManager._propertyMap.set(constructor, props);
|
|
1214
|
+
}
|
|
1215
|
+
return props;
|
|
1193
1216
|
}
|
|
1194
|
-
static _getMergedProperties(
|
|
1217
|
+
static _getMergedProperties(constructor) {
|
|
1195
1218
|
let props = null;
|
|
1196
|
-
let constructor = target.constructor;
|
|
1197
1219
|
while(constructor !== Object.constructor.prototype){
|
|
1198
|
-
let values = PropertyManager.
|
|
1220
|
+
let values = PropertyManager._getProperties(constructor, false);
|
|
1199
1221
|
if (values) {
|
|
1200
1222
|
if (props === null) {
|
|
1201
1223
|
props = Object.create(null);
|
|
@@ -1206,17 +1228,29 @@ class PropertyManager {
|
|
|
1206
1228
|
}
|
|
1207
1229
|
return props;
|
|
1208
1230
|
}
|
|
1231
|
+
static _getClassProperties(clsName, autoAdd = true) {
|
|
1232
|
+
let props = PropertyManager._classMap.get(clsName);
|
|
1233
|
+
if (props === undefined && autoAdd) {
|
|
1234
|
+
props = new ClassProperties(clsName);
|
|
1235
|
+
PropertyManager._classMap.set(clsName, props);
|
|
1236
|
+
}
|
|
1237
|
+
return props;
|
|
1238
|
+
}
|
|
1239
|
+
static _applyClassProperties(clsName, constructor) {
|
|
1240
|
+
let cls = PropertyManager._getClassProperties(clsName, false);
|
|
1241
|
+
if (cls) {
|
|
1242
|
+
return cls.applyProperties(PropertyManager._getProperties(constructor));
|
|
1243
|
+
} else {
|
|
1244
|
+
return PropertyManager._getProperties(constructor, false);
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1209
1247
|
}
|
|
1210
|
-
PropertyManager.
|
|
1248
|
+
PropertyManager._classMap = new Map();
|
|
1249
|
+
PropertyManager._propertyMap = new Map();
|
|
1211
1250
|
function property(target, propertyKey) {
|
|
1212
1251
|
let options = null;
|
|
1213
1252
|
function normalized(target, propertyKey) {
|
|
1214
|
-
|
|
1215
|
-
if (targetMap === undefined) {
|
|
1216
|
-
targetMap = Object.create(null);
|
|
1217
|
-
PropertyManager._propertiesMap.set(target.constructor, targetMap);
|
|
1218
|
-
}
|
|
1219
|
-
targetMap[propertyKey] = options;
|
|
1253
|
+
PropertyManager._getProperties(target.constructor)[propertyKey] = options;
|
|
1220
1254
|
}
|
|
1221
1255
|
if (target === undefined) {
|
|
1222
1256
|
return property({});
|
|
@@ -2290,6 +2324,53 @@ class Plane extends Mesh {
|
|
|
2290
2324
|
}
|
|
2291
2325
|
}
|
|
2292
2326
|
|
|
2327
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2328
|
+
try {
|
|
2329
|
+
var info = gen[key](arg);
|
|
2330
|
+
var value = info.value;
|
|
2331
|
+
} catch (error) {
|
|
2332
|
+
reject(error);
|
|
2333
|
+
return;
|
|
2334
|
+
}
|
|
2335
|
+
if (info.done) resolve(value);
|
|
2336
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
2337
|
+
}
|
|
2338
|
+
function _async_to_generator(fn) {
|
|
2339
|
+
return function() {
|
|
2340
|
+
var self = this, args = arguments;
|
|
2341
|
+
|
|
2342
|
+
return new Promise(function(resolve, reject) {
|
|
2343
|
+
var gen = fn.apply(self, args);
|
|
2344
|
+
|
|
2345
|
+
function _next(value) {
|
|
2346
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
function _throw(err) {
|
|
2350
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
2351
|
+
}
|
|
2352
|
+
|
|
2353
|
+
_next(undefined);
|
|
2354
|
+
});
|
|
2355
|
+
};
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2358
|
+
function _object_without_properties_loose(source, excluded) {
|
|
2359
|
+
if (source == null) return {};
|
|
2360
|
+
|
|
2361
|
+
var target = {};
|
|
2362
|
+
var sourceKeys = Object.keys(source);
|
|
2363
|
+
var key, i;
|
|
2364
|
+
|
|
2365
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
2366
|
+
key = sourceKeys[i];
|
|
2367
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
2368
|
+
target[key] = source[key];
|
|
2369
|
+
}
|
|
2370
|
+
|
|
2371
|
+
return target;
|
|
2372
|
+
}
|
|
2373
|
+
|
|
2293
2374
|
class Caller {
|
|
2294
2375
|
get pause() {
|
|
2295
2376
|
return this._pause;
|
|
@@ -2794,7 +2875,12 @@ class ResourceManager {
|
|
|
2794
2875
|
this._loaders.set(ext, loader);
|
|
2795
2876
|
}
|
|
2796
2877
|
}
|
|
2797
|
-
loadAsset(
|
|
2878
|
+
loadAsset(_param) {
|
|
2879
|
+
var { url, ext, onProgress } = _param, props = _object_without_properties_loose(_param, [
|
|
2880
|
+
"url",
|
|
2881
|
+
"ext",
|
|
2882
|
+
"onProgress"
|
|
2883
|
+
]);
|
|
2798
2884
|
return new Promise((resolve, reject)=>{
|
|
2799
2885
|
const info = ResourceManager._parseURL(url);
|
|
2800
2886
|
const texSettings = ResourceManager._splitTextureSettings(props);
|
|
@@ -2817,7 +2903,7 @@ class ResourceManager {
|
|
|
2817
2903
|
onError: reject
|
|
2818
2904
|
});
|
|
2819
2905
|
} else {
|
|
2820
|
-
reject("missing loader for " + ext);
|
|
2906
|
+
reject("ResourceManager.loadAsset: missing loader for " + ext);
|
|
2821
2907
|
}
|
|
2822
2908
|
}
|
|
2823
2909
|
});
|
|
@@ -2895,7 +2981,7 @@ class PluginManager {
|
|
|
2895
2981
|
return ins;
|
|
2896
2982
|
}
|
|
2897
2983
|
addPlugin(plugin) {
|
|
2898
|
-
const ins =
|
|
2984
|
+
const ins = getClassInstance(plugin);
|
|
2899
2985
|
if (this._pluginsMap.has(ins.constructor)) {
|
|
2900
2986
|
Logger.warn("Plugin already added");
|
|
2901
2987
|
} else {
|
|
@@ -2903,6 +2989,7 @@ class PluginManager {
|
|
|
2903
2989
|
ins.install && ins.install();
|
|
2904
2990
|
this._plugins.push(ins);
|
|
2905
2991
|
this._pluginsMap.set(ins.constructor, ins);
|
|
2992
|
+
PropertyManager._applyClassProperties(ins.type, ins.constructor);
|
|
2906
2993
|
}
|
|
2907
2994
|
return ins;
|
|
2908
2995
|
}
|
|
@@ -2923,9 +3010,6 @@ class PluginManager {
|
|
|
2923
3010
|
}
|
|
2924
3011
|
|
|
2925
3012
|
class Viewer extends EventEmitter {
|
|
2926
|
-
static _getClassInstance(constructor, args = []) {
|
|
2927
|
-
return typeof constructor === "function" ? new constructor(...args) : constructor;
|
|
2928
|
-
}
|
|
2929
3013
|
static _setDirectLightShadow(shadow, props) {
|
|
2930
3014
|
const shadowCamera = shadow.camera;
|
|
2931
3015
|
for(let i = 0; i < props.length && i < 6; i++){
|
|
@@ -3040,6 +3124,7 @@ class Viewer extends EventEmitter {
|
|
|
3040
3124
|
this.addLoader(aGLTFLoader);
|
|
3041
3125
|
this.addLoader(aHDRLoader);
|
|
3042
3126
|
this.addLoader(aTextureLoader);
|
|
3127
|
+
this.addLoader(aJSONLoader);
|
|
3043
3128
|
}
|
|
3044
3129
|
_frame(time) {
|
|
3045
3130
|
this._time = time;
|
|
@@ -3153,20 +3238,30 @@ class Viewer extends EventEmitter {
|
|
|
3153
3238
|
addLoader(Loader) {
|
|
3154
3239
|
this._resourceManager.addLoader(Loader);
|
|
3155
3240
|
}
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
ext,
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3241
|
+
load(_param) {
|
|
3242
|
+
var _this = this;
|
|
3243
|
+
return _async_to_generator(function*() {
|
|
3244
|
+
var { url, ext, onProgress, castShadow = false, receiveShadow = false } = _param, props = _object_without_properties_loose(_param, [
|
|
3245
|
+
"url",
|
|
3246
|
+
"ext",
|
|
3247
|
+
"onProgress",
|
|
3248
|
+
"castShadow",
|
|
3249
|
+
"receiveShadow"
|
|
3250
|
+
]);
|
|
3251
|
+
const node = yield _this.loadAsset({
|
|
3252
|
+
url,
|
|
3253
|
+
ext,
|
|
3254
|
+
onProgress
|
|
3166
3255
|
});
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3256
|
+
if (castShadow || receiveShadow) {
|
|
3257
|
+
node.userData.meshData.meshes.forEach((v)=>{
|
|
3258
|
+
v.castShadow = castShadow;
|
|
3259
|
+
v.receiveShadow = receiveShadow;
|
|
3260
|
+
});
|
|
3261
|
+
}
|
|
3262
|
+
_this.addNode(node, props);
|
|
3263
|
+
return node;
|
|
3264
|
+
})();
|
|
3170
3265
|
}
|
|
3171
3266
|
tween(target) {
|
|
3172
3267
|
return this._tweenManager.tween(target);
|
|
@@ -3215,9 +3310,20 @@ class Viewer extends EventEmitter {
|
|
|
3215
3310
|
removeComponent(node, component) {
|
|
3216
3311
|
return this._componentManager.removeComponent(node, component);
|
|
3217
3312
|
}
|
|
3218
|
-
addNode(object,
|
|
3313
|
+
addNode(object, _param = {}) {
|
|
3314
|
+
var { args, debug, scale, position, rotation, shadowArgs, makeDefault, component, parent = this._scene } = _param, props = _object_without_properties_loose(_param, [
|
|
3315
|
+
"args",
|
|
3316
|
+
"debug",
|
|
3317
|
+
"scale",
|
|
3318
|
+
"position",
|
|
3319
|
+
"rotation",
|
|
3320
|
+
"shadowArgs",
|
|
3321
|
+
"makeDefault",
|
|
3322
|
+
"component",
|
|
3323
|
+
"parent"
|
|
3324
|
+
]);
|
|
3219
3325
|
let node = null;
|
|
3220
|
-
let ins =
|
|
3326
|
+
let ins = getClassInstance(object, args);
|
|
3221
3327
|
if (ins.isObject3D) {
|
|
3222
3328
|
node = ins;
|
|
3223
3329
|
parent.add(ins);
|
|
@@ -3226,7 +3332,7 @@ class Viewer extends EventEmitter {
|
|
|
3226
3332
|
parent.add(node);
|
|
3227
3333
|
this._componentManager.addComponent(node, ins);
|
|
3228
3334
|
} else {
|
|
3229
|
-
throw Error("unsuport object");
|
|
3335
|
+
throw Error("Viewer.addNode: unsuport object");
|
|
3230
3336
|
}
|
|
3231
3337
|
if (component) {
|
|
3232
3338
|
const components = Array.isArray(component) ? component : [
|
|
@@ -3315,7 +3421,7 @@ class Viewer extends EventEmitter {
|
|
|
3315
3421
|
if (target.every((v)=>v.isMaterial)) {
|
|
3316
3422
|
Viewer.CompileMaterial(this._renderer, this._scene, this._camera, target);
|
|
3317
3423
|
} else {
|
|
3318
|
-
throw Error("unsuport material");
|
|
3424
|
+
throw Error("Viewer.compile: unsuport material");
|
|
3319
3425
|
}
|
|
3320
3426
|
} else if (typeof target === "object") {
|
|
3321
3427
|
if (target.isMaterial) {
|
|
@@ -3337,12 +3443,30 @@ class Viewer extends EventEmitter {
|
|
|
3337
3443
|
Viewer.CompileObject3D(this._renderer, this._scene, this._camera, this._scene);
|
|
3338
3444
|
}
|
|
3339
3445
|
}
|
|
3340
|
-
constructor(
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3446
|
+
constructor(_param = {}){
|
|
3447
|
+
var { root, canvas, autoStart = true, autoResize = true, shadows = false, camera = {
|
|
3448
|
+
fov: 45,
|
|
3449
|
+
near: 1,
|
|
3450
|
+
far: 1000,
|
|
3451
|
+
position: new Vector3(0, 0, 4)
|
|
3452
|
+
}, targetFrameRate = -1, colorSpace = SRGBColorSpace, toneMapping = LinearToneMapping, toneMappingExposure = 1, maxDPR = 1.5, path = "", resourcePath = "", dracoPath = "https://www.gstatic.com/draco/v1/decoders/", loader = {}, tasker = {} } = _param, webglOpts = _object_without_properties_loose(_param, [
|
|
3453
|
+
"root",
|
|
3454
|
+
"canvas",
|
|
3455
|
+
"autoStart",
|
|
3456
|
+
"autoResize",
|
|
3457
|
+
"shadows",
|
|
3458
|
+
"camera",
|
|
3459
|
+
"targetFrameRate",
|
|
3460
|
+
"colorSpace",
|
|
3461
|
+
"toneMapping",
|
|
3462
|
+
"toneMappingExposure",
|
|
3463
|
+
"maxDPR",
|
|
3464
|
+
"path",
|
|
3465
|
+
"resourcePath",
|
|
3466
|
+
"dracoPath",
|
|
3467
|
+
"loader",
|
|
3468
|
+
"tasker"
|
|
3469
|
+
]);
|
|
3346
3470
|
super();
|
|
3347
3471
|
this._dpr = 1;
|
|
3348
3472
|
this._width = 1;
|
|
@@ -3422,5 +3546,5 @@ class Plugin extends ObjectInstance {
|
|
|
3422
3546
|
}
|
|
3423
3547
|
}
|
|
3424
3548
|
|
|
3425
|
-
export { Box, CinestationBlendDefinition, CinestationBrain, Component, EventEmitter, FreelookVirtualCamera, Logger, ObjectInstance, Plane, Plugin, PropertyManager, Sphere, SystemInfo, Tween, TweenChain, TweenManager, Viewer, VirtualCamera, aEXRLoader, aFBXLoader, aGLTFLoader, aHDRLoader, aJSONLoader, aTextureLoader, mixin, property };
|
|
3549
|
+
export { Box, CinestationBlendDefinition, CinestationBrain, Component, EventEmitter, FreelookVirtualCamera, Logger, ObjectInstance, Plane, Plugin, PropertyManager, Sphere, SystemInfo, Tween, TweenChain, TweenManager, Viewer, VirtualCamera, aEXRLoader, aFBXLoader, aGLTFLoader, aHDRLoader, aJSONLoader, aTextureLoader, getClassInstance, mixin, property };
|
|
3426
3550
|
//# sourceMappingURL=module.js.map
|