@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/module.js CHANGED
@@ -5,7 +5,7 @@ import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
5
5
  import { MeshoptDecoder } from 'three/examples/jsm/libs/meshopt_decoder.module.js';
6
6
  import * as THREE from 'three';
7
7
  import { EquirectangularReflectionMapping, FileLoader, TextureLoader as TextureLoader$1, SRGBColorSpace, CubeUVReflectionMapping, Mesh, BoxGeometry, SphereGeometry, PlaneGeometry, MathUtils, Vector3, Vector2, LinearInterpolant, Object3D, Plane as Plane$1, Matrix4, Vector4, PerspectiveCamera, WebGLRenderTarget, LinearMipMapLinearFilter, LinearFilter, HalfFloatType, AnimationMixer, Color, OrthographicCamera, MeshDepthMaterial, ShaderMaterial, Euler, Group, REVISION, Box3, Sphere as Sphere$1, Raycaster, Quaternion, Spherical, UniformsUtils, NoBlending, AdditiveBlending, FloatType, UnsignedByteType, LinearSRGBColorSpace, NearestFilter, ClampToEdgeWrapping, WebGLCubeRenderTarget, DataTexture, RGBAFormat, UVMapping, BufferGeometry, Float32BufferAttribute, Scene, WebGLRenderer, LinearToneMapping, PCFSoftShadowMap, LoadingManager, PMREMGenerator, CubeCamera, ShaderLib, ShaderChunk, BufferAttribute, NormalBlending } from 'three';
8
- import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader.js';
8
+ import { HDRLoader as HDRLoader$1 } from 'three/examples/jsm/loaders/HDRLoader.js';
9
9
  import { SVGLoader as SVGLoader$1 } from 'three/examples/jsm/loaders/SVGLoader.js';
10
10
  import { KTX2Loader as KTX2Loader$1 } from 'three/examples/jsm/loaders/KTX2Loader.js';
11
11
  import { HorizontalBlurShader, VerticalBlurShader } from 'three/examples/jsm/Addons.js';
@@ -271,7 +271,7 @@ class HDRLoader extends Loader {
271
271
  load({ url, path, resourcePath, manager, texSettings, onLoad, onProgress, onError }) {
272
272
  let loader = this._loader;
273
273
  if (loader === undefined) {
274
- loader = this._loader = new RGBELoader();
274
+ loader = this._loader = new HDRLoader$1();
275
275
  }
276
276
  loader.manager = manager;
277
277
  loader.setPath(path);
@@ -2627,9 +2627,15 @@ class DeviceInput extends Component {
2627
2627
  get pointerPixel() {
2628
2628
  return this._pointerPixel;
2629
2629
  }
2630
+ get pointerDown() {
2631
+ return this._pointerDown;
2632
+ }
2630
2633
  get pointerButton() {
2631
2634
  return this._pointerButton;
2632
2635
  }
2636
+ get pointerMoving() {
2637
+ return this._pointerMoving;
2638
+ }
2633
2639
  get prePointer() {
2634
2640
  return this._prePointer;
2635
2641
  }
@@ -2657,6 +2663,9 @@ class DeviceInput extends Component {
2657
2663
  get keys() {
2658
2664
  return this._keys;
2659
2665
  }
2666
+ get pressability() {
2667
+ return this._pressability;
2668
+ }
2660
2669
  onEnable() {
2661
2670
  const dom = this._target;
2662
2671
  this._addEventListener(dom, 'contextmenu', (e)=>e.preventDefault());
@@ -2709,6 +2718,8 @@ class DeviceInput extends Component {
2709
2718
  this._listeners = [];
2710
2719
  }
2711
2720
  lastUpdate(dt) {
2721
+ this._pointerDown = false;
2722
+ this._pointerMoving = false;
2712
2723
  this._prePointer.copy(this._pointer);
2713
2724
  this._prePointerPixel.copy(this._pointerPixel);
2714
2725
  for(let i = this._touchCount; i--;){
@@ -2793,6 +2804,7 @@ class DeviceInput extends Component {
2793
2804
  }
2794
2805
  _onPointerDown(e) {
2795
2806
  e = this._remapPointer(e);
2807
+ this._pointerDown = true;
2796
2808
  this._pointerButton = e.button;
2797
2809
  this._computePointer(e);
2798
2810
  this._prePointer.copy(this._pointer);
@@ -2810,6 +2822,7 @@ class DeviceInput extends Component {
2810
2822
  _onPointerMove(e) {
2811
2823
  e = this._remapPointer(e);
2812
2824
  this._computePointer(e);
2825
+ this._pointerMoving = true;
2813
2826
  this._pressability.pointerMove(this._pointer, this.viewer.camera);
2814
2827
  this.viewer.emit(DeviceInput.POINTER_MOVE, e);
2815
2828
  }
@@ -2877,7 +2890,7 @@ class DeviceInput extends Component {
2877
2890
  this.viewer.emit(DeviceInput.KEYUP, e);
2878
2891
  }
2879
2892
  constructor(option){
2880
- super(), this._listeners = [], this._touches = [], this._touchCount = 0, this._touchStart = false, this._touchMoving = false, this._pointer = new Vector2(), this._pointerPixel = new Vector2(), this._pointerButton = -1, this._prePointer = new Vector2(), this._prePointerPixel = new Vector2(), this._preTouches = [], this._mouseWheel = 0, this._keys = {}, this._pressability = new Pressability();
2893
+ super(), this._listeners = [], this._touches = [], this._touchCount = 0, this._touchStart = false, this._touchMoving = false, this._pointer = new Vector2(), this._pointerPixel = new Vector2(), this._pointerButton = -1, this._pointerDown = false, this._pointerMoving = false, this._prePointer = new Vector2(), this._prePointerPixel = new Vector2(), this._preTouches = [], this._mouseWheel = 0, this._keys = {}, this._pressability = new Pressability();
2881
2894
  this._target = option.source;
2882
2895
  this._normalizeWheel = option.normalizeWheel || normalizeWheel;
2883
2896
  }
@@ -3914,6 +3927,12 @@ class ReflectorMaterial extends ShaderMaterial {
3914
3927
  set aoMap(v) {
3915
3928
  this.uniforms.aoMap.value = v;
3916
3929
  }
3930
+ get aoMapIntensity() {
3931
+ return this.uniforms.aoMapIntensity.value;
3932
+ }
3933
+ set aoMapIntensity(v) {
3934
+ this.uniforms.aoMapIntensity.value = v;
3935
+ }
3917
3936
  get lightMap() {
3918
3937
  return this.uniforms.lightMap.value;
3919
3938
  }
@@ -3992,6 +4011,9 @@ class ReflectorMaterial extends ShaderMaterial {
3992
4011
  },
3993
4012
  lightMapIntensity: {
3994
4013
  value: 1
4014
+ },
4015
+ dfgLUT: {
4016
+ value: null
3995
4017
  }
3996
4018
  };
3997
4019
  Object.defineProperty(this, "opacity", {
@@ -4038,6 +4060,12 @@ __decorate([
4038
4060
  __decorate([
4039
4061
  property
4040
4062
  ], ReflectorMaterial.prototype, "aoMap", null);
4063
+ __decorate([
4064
+ property({
4065
+ min: 0,
4066
+ max: 1
4067
+ })
4068
+ ], ReflectorMaterial.prototype, "aoMapIntensity", null);
4041
4069
  __decorate([
4042
4070
  property
4043
4071
  ], ReflectorMaterial.prototype, "lightMap", null);
@@ -4348,6 +4376,9 @@ function _getMipBlurMaterial(lodMax, width, height) {
4348
4376
  }
4349
4377
 
4350
4378
  class TaskManager {
4379
+ get isComplete() {
4380
+ return this._taskIndex >= this._tasks.length;
4381
+ }
4351
4382
  destroy() {
4352
4383
  this._tasks = [];
4353
4384
  this._taskIndex = 0;
@@ -4480,6 +4511,9 @@ class ResourceManager {
4480
4511
  }
4481
4512
  return settings;
4482
4513
  }
4514
+ get isComplete() {
4515
+ return this._loaded >= this._totalCount;
4516
+ }
4483
4517
  destroy() {
4484
4518
  this._loaders.clear();
4485
4519
  }
@@ -4504,6 +4538,7 @@ class ResourceManager {
4504
4538
  ...props,
4505
4539
  onProgress,
4506
4540
  onLoad: (asset)=>{
4541
+ this._loaded++;
4507
4542
  this._resources.set(url, asset);
4508
4543
  resolve(asset);
4509
4544
  },
@@ -4512,6 +4547,7 @@ class ResourceManager {
4512
4547
  reject(err);
4513
4548
  }
4514
4549
  });
4550
+ this._totalCount++;
4515
4551
  } else {
4516
4552
  reject("ResourceManager.loadAsset: missing loader for " + sel);
4517
4553
  }
@@ -4523,6 +4559,8 @@ class ResourceManager {
4523
4559
  constructor(viewer){
4524
4560
  this._loaders = new Map();
4525
4561
  this._resources = new Map();
4562
+ this._loaded = 0;
4563
+ this._totalCount = 0;
4526
4564
  this._viewer = viewer;
4527
4565
  }
4528
4566
  }
@@ -4721,44 +4759,43 @@ class Viewer extends EventEmitter {
4721
4759
  };
4722
4760
  }
4723
4761
  }
4724
- _frame(time) {
4725
- this._time = time;
4726
- if (this._targetFrameRate > -1) {
4727
- const interval = 1 / this._targetFrameRate;
4728
- const delta = this._time - this._lastFrameTime;
4729
- if (delta >= interval) {
4730
- this.loop(this._fixedFrameTime ? interval : this._time - this._lastTime);
4731
- this._lastTime = this._time;
4732
- this._lastFrameTime = this._time - delta % interval;
4762
+ animate() {
4763
+ const loop = (dt)=>{
4764
+ if (!this._active) return;
4765
+ if (this._resourceManager.isComplete) {
4766
+ this._taskManager.isComplete ? this._running = true : this._taskManager.update();
4733
4767
  }
4734
- } else {
4735
- this.loop(this._time - this._lastTime);
4736
- this._lastTime = this._time;
4737
- }
4738
- }
4739
- loop(dt) {
4740
- if (!this._loading) {
4741
- this._taskManager.update();
4742
- if (!this._tasking) {
4743
- this._running = true;
4768
+ if (this._running) {
4769
+ dt = Math.min(dt, 0.067);
4770
+ this._renderer.info.reset();
4771
+ this._componentManager.update(dt);
4772
+ this._componentManager.render(dt);
4744
4773
  }
4745
- }
4746
- if (this._running) {
4747
- dt = Math.min(dt, 0.067);
4748
- this._renderer.info.reset();
4749
- this._componentManager.update(dt);
4750
- this._componentManager.render(dt);
4751
- }
4774
+ };
4775
+ const frame = (time)=>{
4776
+ this._time = time * 0.001;
4777
+ if (this._targetFrameRate > -1) {
4778
+ const interval = 1 / this._targetFrameRate;
4779
+ const delta = this._time - this._lastFrameTime;
4780
+ if (delta >= interval) {
4781
+ loop(this._fixedFrameTime ? interval : this._time - this._lastTime);
4782
+ this._lastTime = this._time;
4783
+ this._lastFrameTime = this._time - delta % interval;
4784
+ }
4785
+ } else {
4786
+ loop(this._time - this._lastTime);
4787
+ this._lastTime = this._time;
4788
+ }
4789
+ };
4790
+ this._renderer.setAnimationLoop(frame);
4752
4791
  }
4753
4792
  start() {
4754
- if (this._active == false) {
4793
+ if (this._active === false) {
4755
4794
  this._active = true;
4756
- const frameCallback = (time)=>{
4757
- if (this._active) {
4758
- this._frame(time * 0.001);
4759
- }
4760
- };
4761
- this._renderer.setAnimationLoop(frameCallback);
4795
+ requestAnimationFrame(()=>{
4796
+ this.rotate();
4797
+ this.resize();
4798
+ });
4762
4799
  }
4763
4800
  return this;
4764
4801
  }
@@ -4898,7 +4935,7 @@ class Viewer extends EventEmitter {
4898
4935
  if (parent === undefined) {
4899
4936
  parent = mount ? this._mount : this._scene;
4900
4937
  }
4901
- if (parent && !node.parent) {
4938
+ if (parent !== node && !node.parent) {
4902
4939
  parent.add(node);
4903
4940
  }
4904
4941
  if (component) {
@@ -5118,7 +5155,7 @@ class Viewer extends EventEmitter {
5118
5155
  width: 1,
5119
5156
  height: 1,
5120
5157
  factor: 1
5121
- }, 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 = ()=>[
5158
+ }, 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 = ()=>[
5122
5159
  window.innerWidth,
5123
5160
  window.innerHeight
5124
5161
  ], this._orientation = Orientation.AUTO;
@@ -5150,14 +5187,8 @@ class Viewer extends EventEmitter {
5150
5187
  this._renderer.sortObjects = sortObjects;
5151
5188
  this._targetFrameRate = targetFrameRate;
5152
5189
  this._windowSize = typeof resize === "function" ? resize : resize === ResizeMode.AUTO ? this._windowSize : null;
5153
- const complete = (set, cb)=>{
5154
- set();
5155
- cb && cb();
5156
- };
5157
- this._taskManager = new TaskManager(()=>complete(()=>this._tasking = false, tasker.onComplete), tasker.onProgress, tasker.onError);
5158
- this._taskManager.onStart = ()=>this._tasking = true;
5159
- this._loadingManager = new LoadingManager(()=>complete(()=>this._loading = false, loader.onComplete), loader.onProgress, loader.onError);
5160
- this._loadingManager.onStart = ()=>this._loading = true;
5190
+ this._taskManager = new TaskManager(tasker.onComplete, tasker.onProgress, tasker.onError);
5191
+ this._loadingManager = new LoadingManager(loader.onComplete, loader.onProgress, loader.onError);
5161
5192
  this._resourceManager = new ResourceManager(this);
5162
5193
  this._componentManager = new ComponentManager(this);
5163
5194
  this._resourceOptions = {
@@ -5182,11 +5213,9 @@ class Viewer extends EventEmitter {
5182
5213
  this.addLoader(BINLoader);
5183
5214
  this.addLoader(SVGLoader);
5184
5215
  this.addLoader(KTX2Loader);
5185
- setTimeout(()=>{
5186
- this.rotate();
5187
- this.resize();
5188
- this.start();
5189
- });
5216
+ this.rotate();
5217
+ this.resize();
5218
+ this.animate();
5190
5219
  }
5191
5220
  }
5192
5221
  Viewer.instanceCount = 0;