@xviewer.js/core 1.0.5-alhpa.0 → 1.0.5-alhpa.2

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.cjs CHANGED
@@ -6,7 +6,7 @@ var GLTFLoader_js = require('three/examples/jsm/loaders/GLTFLoader.js');
6
6
  var DRACOLoader_js = require('three/examples/jsm/loaders/DRACOLoader.js');
7
7
  var meshopt_decoder_module_js = require('three/examples/jsm/libs/meshopt_decoder.module.js');
8
8
  var THREE = require('three');
9
- var RGBELoader_js = require('three/examples/jsm/loaders/RGBELoader.js');
9
+ var HDRLoader_js = require('three/examples/jsm/loaders/HDRLoader.js');
10
10
  var SVGLoader_js = require('three/examples/jsm/loaders/SVGLoader.js');
11
11
  var KTX2Loader_js = require('three/examples/jsm/loaders/KTX2Loader.js');
12
12
  var Addons_js = require('three/examples/jsm/Addons.js');
@@ -291,7 +291,7 @@ class HDRLoader extends Loader {
291
291
  load({ url, path, resourcePath, manager, texSettings, onLoad, onProgress, onError }) {
292
292
  let loader = this._loader;
293
293
  if (loader === undefined) {
294
- loader = this._loader = new RGBELoader_js.RGBELoader();
294
+ loader = this._loader = new HDRLoader_js.HDRLoader();
295
295
  }
296
296
  loader.manager = manager;
297
297
  loader.setPath(path);
@@ -2647,9 +2647,15 @@ class DeviceInput extends Component {
2647
2647
  get pointerPixel() {
2648
2648
  return this._pointerPixel;
2649
2649
  }
2650
+ get pointerDown() {
2651
+ return this._pointerDown;
2652
+ }
2650
2653
  get pointerButton() {
2651
2654
  return this._pointerButton;
2652
2655
  }
2656
+ get pointerMoving() {
2657
+ return this._pointerMoving;
2658
+ }
2653
2659
  get prePointer() {
2654
2660
  return this._prePointer;
2655
2661
  }
@@ -2677,6 +2683,9 @@ class DeviceInput extends Component {
2677
2683
  get keys() {
2678
2684
  return this._keys;
2679
2685
  }
2686
+ get pressability() {
2687
+ return this._pressability;
2688
+ }
2680
2689
  onEnable() {
2681
2690
  const dom = this._target;
2682
2691
  this._addEventListener(dom, 'contextmenu', (e)=>e.preventDefault());
@@ -2729,6 +2738,8 @@ class DeviceInput extends Component {
2729
2738
  this._listeners = [];
2730
2739
  }
2731
2740
  lastUpdate(dt) {
2741
+ this._pointerDown = false;
2742
+ this._pointerMoving = false;
2732
2743
  this._prePointer.copy(this._pointer);
2733
2744
  this._prePointerPixel.copy(this._pointerPixel);
2734
2745
  for(let i = this._touchCount; i--;){
@@ -2813,6 +2824,7 @@ class DeviceInput extends Component {
2813
2824
  }
2814
2825
  _onPointerDown(e) {
2815
2826
  e = this._remapPointer(e);
2827
+ this._pointerDown = true;
2816
2828
  this._pointerButton = e.button;
2817
2829
  this._computePointer(e);
2818
2830
  this._prePointer.copy(this._pointer);
@@ -2830,6 +2842,7 @@ class DeviceInput extends Component {
2830
2842
  _onPointerMove(e) {
2831
2843
  e = this._remapPointer(e);
2832
2844
  this._computePointer(e);
2845
+ this._pointerMoving = true;
2833
2846
  this._pressability.pointerMove(this._pointer, this.viewer.camera);
2834
2847
  this.viewer.emit(DeviceInput.POINTER_MOVE, e);
2835
2848
  }
@@ -2897,7 +2910,7 @@ class DeviceInput extends Component {
2897
2910
  this.viewer.emit(DeviceInput.KEYUP, e);
2898
2911
  }
2899
2912
  constructor(option){
2900
- super(), this._listeners = [], this._touches = [], this._touchCount = 0, this._touchStart = false, this._touchMoving = false, this._pointer = new THREE.Vector2(), this._pointerPixel = new THREE.Vector2(), this._pointerButton = -1, this._prePointer = new THREE.Vector2(), this._prePointerPixel = new THREE.Vector2(), this._preTouches = [], this._mouseWheel = 0, this._keys = {}, this._pressability = new Pressability();
2913
+ super(), this._listeners = [], this._touches = [], this._touchCount = 0, this._touchStart = false, this._touchMoving = false, this._pointer = new THREE.Vector2(), this._pointerPixel = new THREE.Vector2(), this._pointerButton = -1, this._pointerDown = false, this._pointerMoving = false, this._prePointer = new THREE.Vector2(), this._prePointerPixel = new THREE.Vector2(), this._preTouches = [], this._mouseWheel = 0, this._keys = {}, this._pressability = new Pressability();
2901
2914
  this._target = option.source;
2902
2915
  this._normalizeWheel = option.normalizeWheel || normalizeWheel;
2903
2916
  }
@@ -3934,6 +3947,12 @@ class ReflectorMaterial extends THREE.ShaderMaterial {
3934
3947
  set aoMap(v) {
3935
3948
  this.uniforms.aoMap.value = v;
3936
3949
  }
3950
+ get aoMapIntensity() {
3951
+ return this.uniforms.aoMapIntensity.value;
3952
+ }
3953
+ set aoMapIntensity(v) {
3954
+ this.uniforms.aoMapIntensity.value = v;
3955
+ }
3937
3956
  get lightMap() {
3938
3957
  return this.uniforms.lightMap.value;
3939
3958
  }
@@ -4012,6 +4031,9 @@ class ReflectorMaterial extends THREE.ShaderMaterial {
4012
4031
  },
4013
4032
  lightMapIntensity: {
4014
4033
  value: 1
4034
+ },
4035
+ dfgLUT: {
4036
+ value: null
4015
4037
  }
4016
4038
  };
4017
4039
  Object.defineProperty(this, "opacity", {
@@ -4058,6 +4080,12 @@ __decorate([
4058
4080
  __decorate([
4059
4081
  property
4060
4082
  ], ReflectorMaterial.prototype, "aoMap", null);
4083
+ __decorate([
4084
+ property({
4085
+ min: 0,
4086
+ max: 1
4087
+ })
4088
+ ], ReflectorMaterial.prototype, "aoMapIntensity", null);
4061
4089
  __decorate([
4062
4090
  property
4063
4091
  ], ReflectorMaterial.prototype, "lightMap", null);
@@ -4368,6 +4396,9 @@ function _getMipBlurMaterial(lodMax, width, height) {
4368
4396
  }
4369
4397
 
4370
4398
  class TaskManager {
4399
+ get isComplete() {
4400
+ return this._taskIndex >= this._tasks.length;
4401
+ }
4371
4402
  destroy() {
4372
4403
  this._tasks = [];
4373
4404
  this._taskIndex = 0;
@@ -4500,6 +4531,9 @@ class ResourceManager {
4500
4531
  }
4501
4532
  return settings;
4502
4533
  }
4534
+ get isComplete() {
4535
+ return this._loaded >= this._totalCount;
4536
+ }
4503
4537
  destroy() {
4504
4538
  this._loaders.clear();
4505
4539
  }
@@ -4524,6 +4558,7 @@ class ResourceManager {
4524
4558
  ...props,
4525
4559
  onProgress,
4526
4560
  onLoad: (asset)=>{
4561
+ this._loaded++;
4527
4562
  this._resources.set(url, asset);
4528
4563
  resolve(asset);
4529
4564
  },
@@ -4532,6 +4567,7 @@ class ResourceManager {
4532
4567
  reject(err);
4533
4568
  }
4534
4569
  });
4570
+ this._totalCount++;
4535
4571
  } else {
4536
4572
  reject("ResourceManager.loadAsset: missing loader for " + sel);
4537
4573
  }
@@ -4543,6 +4579,8 @@ class ResourceManager {
4543
4579
  constructor(viewer){
4544
4580
  this._loaders = new Map();
4545
4581
  this._resources = new Map();
4582
+ this._loaded = 0;
4583
+ this._totalCount = 0;
4546
4584
  this._viewer = viewer;
4547
4585
  }
4548
4586
  }
@@ -4741,44 +4779,43 @@ class Viewer extends EventEmitter {
4741
4779
  };
4742
4780
  }
4743
4781
  }
4744
- _frame(time) {
4745
- this._time = time;
4746
- if (this._targetFrameRate > -1) {
4747
- const interval = 1 / this._targetFrameRate;
4748
- const delta = this._time - this._lastFrameTime;
4749
- if (delta >= interval) {
4750
- this.loop(this._fixedFrameTime ? interval : this._time - this._lastTime);
4751
- this._lastTime = this._time;
4752
- this._lastFrameTime = this._time - delta % interval;
4782
+ animate() {
4783
+ const loop = (dt)=>{
4784
+ if (!this._active) return;
4785
+ if (this._resourceManager.isComplete) {
4786
+ this._taskManager.isComplete ? this._running = true : this._taskManager.update();
4753
4787
  }
4754
- } else {
4755
- this.loop(this._time - this._lastTime);
4756
- this._lastTime = this._time;
4757
- }
4758
- }
4759
- loop(dt) {
4760
- if (!this._loading) {
4761
- this._taskManager.update();
4762
- if (!this._tasking) {
4763
- this._running = true;
4788
+ if (this._running) {
4789
+ dt = Math.min(dt, 0.067);
4790
+ this._renderer.info.reset();
4791
+ this._componentManager.update(dt);
4792
+ this._componentManager.render(dt);
4764
4793
  }
4765
- }
4766
- if (this._running) {
4767
- dt = Math.min(dt, 0.067);
4768
- this._renderer.info.reset();
4769
- this._componentManager.update(dt);
4770
- this._componentManager.render(dt);
4771
- }
4794
+ };
4795
+ const frame = (time)=>{
4796
+ this._time = time * 0.001;
4797
+ if (this._targetFrameRate > -1) {
4798
+ const interval = 1 / this._targetFrameRate;
4799
+ const delta = this._time - this._lastFrameTime;
4800
+ if (delta >= interval) {
4801
+ loop(this._fixedFrameTime ? interval : this._time - this._lastTime);
4802
+ this._lastTime = this._time;
4803
+ this._lastFrameTime = this._time - delta % interval;
4804
+ }
4805
+ } else {
4806
+ loop(this._time - this._lastTime);
4807
+ this._lastTime = this._time;
4808
+ }
4809
+ };
4810
+ this._renderer.setAnimationLoop(frame);
4772
4811
  }
4773
4812
  start() {
4774
- if (this._active == false) {
4813
+ if (this._active === false) {
4775
4814
  this._active = true;
4776
- const frameCallback = (time)=>{
4777
- if (this._active) {
4778
- this._frame(time * 0.001);
4779
- }
4780
- };
4781
- this._renderer.setAnimationLoop(frameCallback);
4815
+ requestAnimationFrame(()=>{
4816
+ this.rotate();
4817
+ this.resize();
4818
+ });
4782
4819
  }
4783
4820
  return this;
4784
4821
  }
@@ -4918,7 +4955,7 @@ class Viewer extends EventEmitter {
4918
4955
  if (parent === undefined) {
4919
4956
  parent = mount ? this._mount : this._scene;
4920
4957
  }
4921
- if (parent && !node.parent) {
4958
+ if (parent !== node && !node.parent) {
4922
4959
  parent.add(node);
4923
4960
  }
4924
4961
  if (component) {
@@ -5138,7 +5175,7 @@ class Viewer extends EventEmitter {
5138
5175
  width: 1,
5139
5176
  height: 1,
5140
5177
  factor: 1
5141
- }, this._active = false, this._loading = false, this._tasking = false, this._running = false, this._rootRotated = false, this._time = 0, this._lastTime = 0, this._lastFrameTime = 0, this._targetFrameRate = -1, this._fixedFrameTime = false, this._windowSize = ()=>[
5178
+ }, this._active = false, this._running = false, this._rootRotated = false, this._time = 0, this._lastTime = 0, this._lastFrameTime = 0, this._targetFrameRate = -1, this._fixedFrameTime = false, this._windowSize = ()=>[
5142
5179
  window.innerWidth,
5143
5180
  window.innerHeight
5144
5181
  ], this._orientation = Orientation.AUTO;
@@ -5170,14 +5207,8 @@ class Viewer extends EventEmitter {
5170
5207
  this._renderer.sortObjects = sortObjects;
5171
5208
  this._targetFrameRate = targetFrameRate;
5172
5209
  this._windowSize = typeof resize === "function" ? resize : resize === ResizeMode.AUTO ? this._windowSize : null;
5173
- const complete = (set, cb)=>{
5174
- set();
5175
- cb && cb();
5176
- };
5177
- this._taskManager = new TaskManager(()=>complete(()=>this._tasking = false, tasker.onComplete), tasker.onProgress, tasker.onError);
5178
- this._taskManager.onStart = ()=>this._tasking = true;
5179
- this._loadingManager = new THREE.LoadingManager(()=>complete(()=>this._loading = false, loader.onComplete), loader.onProgress, loader.onError);
5180
- this._loadingManager.onStart = ()=>this._loading = true;
5210
+ this._taskManager = new TaskManager(tasker.onComplete, tasker.onProgress, tasker.onError);
5211
+ this._loadingManager = new THREE.LoadingManager(loader.onComplete, loader.onProgress, loader.onError);
5181
5212
  this._resourceManager = new ResourceManager(this);
5182
5213
  this._componentManager = new ComponentManager(this);
5183
5214
  this._resourceOptions = {
@@ -5202,11 +5233,9 @@ class Viewer extends EventEmitter {
5202
5233
  this.addLoader(BINLoader);
5203
5234
  this.addLoader(SVGLoader);
5204
5235
  this.addLoader(KTX2Loader);
5205
- setTimeout(()=>{
5206
- this.rotate();
5207
- this.resize();
5208
- this.start();
5209
- });
5236
+ this.rotate();
5237
+ this.resize();
5238
+ this.animate();
5210
5239
  }
5211
5240
  }
5212
5241
  Viewer.instanceCount = 0;