@xviewer.js/core 1.0.0-alpha.13 → 1.0.0-alpha.14

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/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, LinearToneMapping } from 'three';
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 _getProperties(target) {
1189
- return PropertyManager._propertiesMap.get(target.constructor);
1206
+ static _hasProperties(constructor) {
1207
+ return PropertyManager._propertyMap.has(constructor);
1190
1208
  }
1191
- static _hasProperties(target) {
1192
- return PropertyManager._propertiesMap.has(target.constructor);
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(target) {
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._propertiesMap.get(constructor);
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._propertiesMap = new Map();
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
- let targetMap = PropertyManager._propertiesMap.get(target.constructor);
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({ url, ext, onProgress, ...props }) {
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);
@@ -2895,7 +2981,7 @@ class PluginManager {
2895
2981
  return ins;
2896
2982
  }
2897
2983
  addPlugin(plugin) {
2898
- const ins = Viewer._getClassInstance(plugin);
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++){
@@ -3153,20 +3237,30 @@ class Viewer extends EventEmitter {
3153
3237
  addLoader(Loader) {
3154
3238
  this._resourceManager.addLoader(Loader);
3155
3239
  }
3156
- async load({ url, ext, onProgress, castShadow = false, receiveShadow = false, ...props }) {
3157
- const node = await this.loadAsset({
3158
- url,
3159
- ext,
3160
- onProgress
3161
- });
3162
- if (castShadow || receiveShadow) {
3163
- node.userData.meshData.meshes.forEach((v)=>{
3164
- v.castShadow = castShadow;
3165
- v.receiveShadow = receiveShadow;
3240
+ load(_param) {
3241
+ var _this = this;
3242
+ return _async_to_generator(function*() {
3243
+ var { url, ext, onProgress, castShadow = false, receiveShadow = false } = _param, props = _object_without_properties_loose(_param, [
3244
+ "url",
3245
+ "ext",
3246
+ "onProgress",
3247
+ "castShadow",
3248
+ "receiveShadow"
3249
+ ]);
3250
+ const node = yield _this.loadAsset({
3251
+ url,
3252
+ ext,
3253
+ onProgress
3166
3254
  });
3167
- }
3168
- this.addNode(node, props);
3169
- return node;
3255
+ if (castShadow || receiveShadow) {
3256
+ node.userData.meshData.meshes.forEach((v)=>{
3257
+ v.castShadow = castShadow;
3258
+ v.receiveShadow = receiveShadow;
3259
+ });
3260
+ }
3261
+ _this.addNode(node, props);
3262
+ return node;
3263
+ })();
3170
3264
  }
3171
3265
  tween(target) {
3172
3266
  return this._tweenManager.tween(target);
@@ -3215,9 +3309,20 @@ class Viewer extends EventEmitter {
3215
3309
  removeComponent(node, component) {
3216
3310
  return this._componentManager.removeComponent(node, component);
3217
3311
  }
3218
- addNode(object, { args, debug, scale, position, rotation, shadowArgs, makeDefault, component, parent = this._scene, ...props } = {}) {
3312
+ addNode(object, _param = {}) {
3313
+ var { args, debug, scale, position, rotation, shadowArgs, makeDefault, component, parent = this._scene } = _param, props = _object_without_properties_loose(_param, [
3314
+ "args",
3315
+ "debug",
3316
+ "scale",
3317
+ "position",
3318
+ "rotation",
3319
+ "shadowArgs",
3320
+ "makeDefault",
3321
+ "component",
3322
+ "parent"
3323
+ ]);
3219
3324
  let node = null;
3220
- let ins = Viewer._getClassInstance(object, args);
3325
+ let ins = getClassInstance(object, args);
3221
3326
  if (ins.isObject3D) {
3222
3327
  node = ins;
3223
3328
  parent.add(ins);
@@ -3337,12 +3442,30 @@ class Viewer extends EventEmitter {
3337
3442
  Viewer.CompileObject3D(this._renderer, this._scene, this._camera, this._scene);
3338
3443
  }
3339
3444
  }
3340
- constructor({ root, canvas, autoStart = true, autoResize = true, shadows = false, camera = {
3341
- fov: 45,
3342
- near: 1,
3343
- far: 1000,
3344
- position: new Vector3(0, 0, 4)
3345
- }, targetFrameRate = -1, colorSpace = SRGBColorSpace, toneMapping = LinearToneMapping, toneMappingExposure = 1, maxDPR = 1.5, path = "", resourcePath = "", dracoPath = "https://www.gstatic.com/draco/v1/decoders/", loader = {}, tasker = {}, ...webglOpts } = {}){
3445
+ constructor(_param = {}){
3446
+ var { root, canvas, autoStart = true, autoResize = true, shadows = false, camera = {
3447
+ fov: 45,
3448
+ near: 1,
3449
+ far: 1000,
3450
+ position: new Vector3(0, 0, 4)
3451
+ }, 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, [
3452
+ "root",
3453
+ "canvas",
3454
+ "autoStart",
3455
+ "autoResize",
3456
+ "shadows",
3457
+ "camera",
3458
+ "targetFrameRate",
3459
+ "colorSpace",
3460
+ "toneMapping",
3461
+ "toneMappingExposure",
3462
+ "maxDPR",
3463
+ "path",
3464
+ "resourcePath",
3465
+ "dracoPath",
3466
+ "loader",
3467
+ "tasker"
3468
+ ]);
3346
3469
  super();
3347
3470
  this._dpr = 1;
3348
3471
  this._width = 1;
@@ -3422,5 +3545,5 @@ class Plugin extends ObjectInstance {
3422
3545
  }
3423
3546
  }
3424
3547
 
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 };
3548
+ 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
3549
  //# sourceMappingURL=module.js.map