@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/main.js
CHANGED
|
@@ -137,6 +137,10 @@ function mixin(derivedCtor, baseCtors) {
|
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
function getClassInstance(constructor, args = []) {
|
|
141
|
+
return typeof constructor === "function" ? new constructor(...args) : constructor;
|
|
142
|
+
}
|
|
143
|
+
|
|
140
144
|
/**
|
|
141
145
|
* The Ease class provides a collection of easing functions for use with tween.js.
|
|
142
146
|
*/ var Easing = {
|
|
@@ -1186,18 +1190,36 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
1186
1190
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1187
1191
|
};
|
|
1188
1192
|
|
|
1193
|
+
class ClassProperties {
|
|
1194
|
+
property(propertyKey, options = {}) {
|
|
1195
|
+
this._properties[propertyKey] = options;
|
|
1196
|
+
return this;
|
|
1197
|
+
}
|
|
1198
|
+
applyProperties(target) {
|
|
1199
|
+
Object.assign(target, this._properties);
|
|
1200
|
+
return target;
|
|
1201
|
+
}
|
|
1202
|
+
constructor(clsName){
|
|
1203
|
+
this.clsName = clsName;
|
|
1204
|
+
this._properties = Object.create(null);
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1189
1207
|
class PropertyManager {
|
|
1190
|
-
static
|
|
1191
|
-
return PropertyManager.
|
|
1208
|
+
static _hasProperties(constructor) {
|
|
1209
|
+
return PropertyManager._propertyMap.has(constructor);
|
|
1192
1210
|
}
|
|
1193
|
-
static
|
|
1194
|
-
|
|
1211
|
+
static _getProperties(constructor, autoAdd = true) {
|
|
1212
|
+
let props = PropertyManager._propertyMap.get(constructor);
|
|
1213
|
+
if (props === undefined && autoAdd) {
|
|
1214
|
+
props = Object.create(null);
|
|
1215
|
+
PropertyManager._propertyMap.set(constructor, props);
|
|
1216
|
+
}
|
|
1217
|
+
return props;
|
|
1195
1218
|
}
|
|
1196
|
-
static _getMergedProperties(
|
|
1219
|
+
static _getMergedProperties(constructor) {
|
|
1197
1220
|
let props = null;
|
|
1198
|
-
let constructor = target.constructor;
|
|
1199
1221
|
while(constructor !== Object.constructor.prototype){
|
|
1200
|
-
let values = PropertyManager.
|
|
1222
|
+
let values = PropertyManager._getProperties(constructor, false);
|
|
1201
1223
|
if (values) {
|
|
1202
1224
|
if (props === null) {
|
|
1203
1225
|
props = Object.create(null);
|
|
@@ -1208,17 +1230,29 @@ class PropertyManager {
|
|
|
1208
1230
|
}
|
|
1209
1231
|
return props;
|
|
1210
1232
|
}
|
|
1233
|
+
static _getClassProperties(clsName, autoAdd = true) {
|
|
1234
|
+
let props = PropertyManager._classMap.get(clsName);
|
|
1235
|
+
if (props === undefined && autoAdd) {
|
|
1236
|
+
props = new ClassProperties(clsName);
|
|
1237
|
+
PropertyManager._classMap.set(clsName, props);
|
|
1238
|
+
}
|
|
1239
|
+
return props;
|
|
1240
|
+
}
|
|
1241
|
+
static _applyClassProperties(clsName, constructor) {
|
|
1242
|
+
let cls = PropertyManager._getClassProperties(clsName, false);
|
|
1243
|
+
if (cls) {
|
|
1244
|
+
return cls.applyProperties(PropertyManager._getProperties(constructor));
|
|
1245
|
+
} else {
|
|
1246
|
+
return PropertyManager._getProperties(constructor, false);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1211
1249
|
}
|
|
1212
|
-
PropertyManager.
|
|
1250
|
+
PropertyManager._classMap = new Map();
|
|
1251
|
+
PropertyManager._propertyMap = new Map();
|
|
1213
1252
|
function property(target, propertyKey) {
|
|
1214
1253
|
let options = null;
|
|
1215
1254
|
function normalized(target, propertyKey) {
|
|
1216
|
-
|
|
1217
|
-
if (targetMap === undefined) {
|
|
1218
|
-
targetMap = Object.create(null);
|
|
1219
|
-
PropertyManager._propertiesMap.set(target.constructor, targetMap);
|
|
1220
|
-
}
|
|
1221
|
-
targetMap[propertyKey] = options;
|
|
1255
|
+
PropertyManager._getProperties(target.constructor)[propertyKey] = options;
|
|
1222
1256
|
}
|
|
1223
1257
|
if (target === undefined) {
|
|
1224
1258
|
return property({});
|
|
@@ -2292,6 +2326,53 @@ class Plane extends three.Mesh {
|
|
|
2292
2326
|
}
|
|
2293
2327
|
}
|
|
2294
2328
|
|
|
2329
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2330
|
+
try {
|
|
2331
|
+
var info = gen[key](arg);
|
|
2332
|
+
var value = info.value;
|
|
2333
|
+
} catch (error) {
|
|
2334
|
+
reject(error);
|
|
2335
|
+
return;
|
|
2336
|
+
}
|
|
2337
|
+
if (info.done) resolve(value);
|
|
2338
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
2339
|
+
}
|
|
2340
|
+
function _async_to_generator(fn) {
|
|
2341
|
+
return function() {
|
|
2342
|
+
var self = this, args = arguments;
|
|
2343
|
+
|
|
2344
|
+
return new Promise(function(resolve, reject) {
|
|
2345
|
+
var gen = fn.apply(self, args);
|
|
2346
|
+
|
|
2347
|
+
function _next(value) {
|
|
2348
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2351
|
+
function _throw(err) {
|
|
2352
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
_next(undefined);
|
|
2356
|
+
});
|
|
2357
|
+
};
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
function _object_without_properties_loose(source, excluded) {
|
|
2361
|
+
if (source == null) return {};
|
|
2362
|
+
|
|
2363
|
+
var target = {};
|
|
2364
|
+
var sourceKeys = Object.keys(source);
|
|
2365
|
+
var key, i;
|
|
2366
|
+
|
|
2367
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
2368
|
+
key = sourceKeys[i];
|
|
2369
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
2370
|
+
target[key] = source[key];
|
|
2371
|
+
}
|
|
2372
|
+
|
|
2373
|
+
return target;
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2295
2376
|
class Caller {
|
|
2296
2377
|
get pause() {
|
|
2297
2378
|
return this._pause;
|
|
@@ -2796,7 +2877,12 @@ class ResourceManager {
|
|
|
2796
2877
|
this._loaders.set(ext, loader);
|
|
2797
2878
|
}
|
|
2798
2879
|
}
|
|
2799
|
-
loadAsset(
|
|
2880
|
+
loadAsset(_param) {
|
|
2881
|
+
var { url, ext, onProgress } = _param, props = _object_without_properties_loose(_param, [
|
|
2882
|
+
"url",
|
|
2883
|
+
"ext",
|
|
2884
|
+
"onProgress"
|
|
2885
|
+
]);
|
|
2800
2886
|
return new Promise((resolve, reject)=>{
|
|
2801
2887
|
const info = ResourceManager._parseURL(url);
|
|
2802
2888
|
const texSettings = ResourceManager._splitTextureSettings(props);
|
|
@@ -2819,7 +2905,7 @@ class ResourceManager {
|
|
|
2819
2905
|
onError: reject
|
|
2820
2906
|
});
|
|
2821
2907
|
} else {
|
|
2822
|
-
reject("missing loader for " + ext);
|
|
2908
|
+
reject("ResourceManager.loadAsset: missing loader for " + ext);
|
|
2823
2909
|
}
|
|
2824
2910
|
}
|
|
2825
2911
|
});
|
|
@@ -2897,7 +2983,7 @@ class PluginManager {
|
|
|
2897
2983
|
return ins;
|
|
2898
2984
|
}
|
|
2899
2985
|
addPlugin(plugin) {
|
|
2900
|
-
const ins =
|
|
2986
|
+
const ins = getClassInstance(plugin);
|
|
2901
2987
|
if (this._pluginsMap.has(ins.constructor)) {
|
|
2902
2988
|
Logger.warn("Plugin already added");
|
|
2903
2989
|
} else {
|
|
@@ -2905,6 +2991,7 @@ class PluginManager {
|
|
|
2905
2991
|
ins.install && ins.install();
|
|
2906
2992
|
this._plugins.push(ins);
|
|
2907
2993
|
this._pluginsMap.set(ins.constructor, ins);
|
|
2994
|
+
PropertyManager._applyClassProperties(ins.type, ins.constructor);
|
|
2908
2995
|
}
|
|
2909
2996
|
return ins;
|
|
2910
2997
|
}
|
|
@@ -2925,9 +3012,6 @@ class PluginManager {
|
|
|
2925
3012
|
}
|
|
2926
3013
|
|
|
2927
3014
|
class Viewer extends EventEmitter {
|
|
2928
|
-
static _getClassInstance(constructor, args = []) {
|
|
2929
|
-
return typeof constructor === "function" ? new constructor(...args) : constructor;
|
|
2930
|
-
}
|
|
2931
3015
|
static _setDirectLightShadow(shadow, props) {
|
|
2932
3016
|
const shadowCamera = shadow.camera;
|
|
2933
3017
|
for(let i = 0; i < props.length && i < 6; i++){
|
|
@@ -3042,6 +3126,7 @@ class Viewer extends EventEmitter {
|
|
|
3042
3126
|
this.addLoader(aGLTFLoader);
|
|
3043
3127
|
this.addLoader(aHDRLoader);
|
|
3044
3128
|
this.addLoader(aTextureLoader);
|
|
3129
|
+
this.addLoader(aJSONLoader);
|
|
3045
3130
|
}
|
|
3046
3131
|
_frame(time) {
|
|
3047
3132
|
this._time = time;
|
|
@@ -3155,20 +3240,30 @@ class Viewer extends EventEmitter {
|
|
|
3155
3240
|
addLoader(Loader) {
|
|
3156
3241
|
this._resourceManager.addLoader(Loader);
|
|
3157
3242
|
}
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
ext,
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3243
|
+
load(_param) {
|
|
3244
|
+
var _this = this;
|
|
3245
|
+
return _async_to_generator(function*() {
|
|
3246
|
+
var { url, ext, onProgress, castShadow = false, receiveShadow = false } = _param, props = _object_without_properties_loose(_param, [
|
|
3247
|
+
"url",
|
|
3248
|
+
"ext",
|
|
3249
|
+
"onProgress",
|
|
3250
|
+
"castShadow",
|
|
3251
|
+
"receiveShadow"
|
|
3252
|
+
]);
|
|
3253
|
+
const node = yield _this.loadAsset({
|
|
3254
|
+
url,
|
|
3255
|
+
ext,
|
|
3256
|
+
onProgress
|
|
3168
3257
|
});
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3258
|
+
if (castShadow || receiveShadow) {
|
|
3259
|
+
node.userData.meshData.meshes.forEach((v)=>{
|
|
3260
|
+
v.castShadow = castShadow;
|
|
3261
|
+
v.receiveShadow = receiveShadow;
|
|
3262
|
+
});
|
|
3263
|
+
}
|
|
3264
|
+
_this.addNode(node, props);
|
|
3265
|
+
return node;
|
|
3266
|
+
})();
|
|
3172
3267
|
}
|
|
3173
3268
|
tween(target) {
|
|
3174
3269
|
return this._tweenManager.tween(target);
|
|
@@ -3217,9 +3312,20 @@ class Viewer extends EventEmitter {
|
|
|
3217
3312
|
removeComponent(node, component) {
|
|
3218
3313
|
return this._componentManager.removeComponent(node, component);
|
|
3219
3314
|
}
|
|
3220
|
-
addNode(object,
|
|
3315
|
+
addNode(object, _param = {}) {
|
|
3316
|
+
var { args, debug, scale, position, rotation, shadowArgs, makeDefault, component, parent = this._scene } = _param, props = _object_without_properties_loose(_param, [
|
|
3317
|
+
"args",
|
|
3318
|
+
"debug",
|
|
3319
|
+
"scale",
|
|
3320
|
+
"position",
|
|
3321
|
+
"rotation",
|
|
3322
|
+
"shadowArgs",
|
|
3323
|
+
"makeDefault",
|
|
3324
|
+
"component",
|
|
3325
|
+
"parent"
|
|
3326
|
+
]);
|
|
3221
3327
|
let node = null;
|
|
3222
|
-
let ins =
|
|
3328
|
+
let ins = getClassInstance(object, args);
|
|
3223
3329
|
if (ins.isObject3D) {
|
|
3224
3330
|
node = ins;
|
|
3225
3331
|
parent.add(ins);
|
|
@@ -3228,7 +3334,7 @@ class Viewer extends EventEmitter {
|
|
|
3228
3334
|
parent.add(node);
|
|
3229
3335
|
this._componentManager.addComponent(node, ins);
|
|
3230
3336
|
} else {
|
|
3231
|
-
throw Error("unsuport object");
|
|
3337
|
+
throw Error("Viewer.addNode: unsuport object");
|
|
3232
3338
|
}
|
|
3233
3339
|
if (component) {
|
|
3234
3340
|
const components = Array.isArray(component) ? component : [
|
|
@@ -3317,7 +3423,7 @@ class Viewer extends EventEmitter {
|
|
|
3317
3423
|
if (target.every((v)=>v.isMaterial)) {
|
|
3318
3424
|
Viewer.CompileMaterial(this._renderer, this._scene, this._camera, target);
|
|
3319
3425
|
} else {
|
|
3320
|
-
throw Error("unsuport material");
|
|
3426
|
+
throw Error("Viewer.compile: unsuport material");
|
|
3321
3427
|
}
|
|
3322
3428
|
} else if (typeof target === "object") {
|
|
3323
3429
|
if (target.isMaterial) {
|
|
@@ -3339,12 +3445,30 @@ class Viewer extends EventEmitter {
|
|
|
3339
3445
|
Viewer.CompileObject3D(this._renderer, this._scene, this._camera, this._scene);
|
|
3340
3446
|
}
|
|
3341
3447
|
}
|
|
3342
|
-
constructor(
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3448
|
+
constructor(_param = {}){
|
|
3449
|
+
var { root, canvas, autoStart = true, autoResize = true, shadows = false, camera = {
|
|
3450
|
+
fov: 45,
|
|
3451
|
+
near: 1,
|
|
3452
|
+
far: 1000,
|
|
3453
|
+
position: new three.Vector3(0, 0, 4)
|
|
3454
|
+
}, targetFrameRate = -1, colorSpace = three.SRGBColorSpace, toneMapping = three.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, [
|
|
3455
|
+
"root",
|
|
3456
|
+
"canvas",
|
|
3457
|
+
"autoStart",
|
|
3458
|
+
"autoResize",
|
|
3459
|
+
"shadows",
|
|
3460
|
+
"camera",
|
|
3461
|
+
"targetFrameRate",
|
|
3462
|
+
"colorSpace",
|
|
3463
|
+
"toneMapping",
|
|
3464
|
+
"toneMappingExposure",
|
|
3465
|
+
"maxDPR",
|
|
3466
|
+
"path",
|
|
3467
|
+
"resourcePath",
|
|
3468
|
+
"dracoPath",
|
|
3469
|
+
"loader",
|
|
3470
|
+
"tasker"
|
|
3471
|
+
]);
|
|
3348
3472
|
super();
|
|
3349
3473
|
this._dpr = 1;
|
|
3350
3474
|
this._width = 1;
|
|
@@ -3448,6 +3572,7 @@ exports.aGLTFLoader = aGLTFLoader;
|
|
|
3448
3572
|
exports.aHDRLoader = aHDRLoader;
|
|
3449
3573
|
exports.aJSONLoader = aJSONLoader;
|
|
3450
3574
|
exports.aTextureLoader = aTextureLoader;
|
|
3575
|
+
exports.getClassInstance = getClassInstance;
|
|
3451
3576
|
exports.mixin = mixin;
|
|
3452
3577
|
exports.property = property;
|
|
3453
3578
|
//# sourceMappingURL=main.js.map
|