@xviewer.js/core 1.0.0-alpha.58 → 1.0.0-alpha.59

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 CHANGED
@@ -1137,7 +1137,7 @@ class aFBXLoader extends aLoader {
1137
1137
  onLoad(aLoader._setUserData(node));
1138
1138
  };
1139
1139
  if (buffer) {
1140
- loadCallback(loader.parse(buffer, path));
1140
+ loadCallback(loader.parse(buffer, resourcePath));
1141
1141
  } else {
1142
1142
  loader.load(url, loadCallback, onProgress, onError);
1143
1143
  }
@@ -3179,6 +3179,73 @@ class Reflector extends Component {
3179
3179
  }
3180
3180
  }
3181
3181
 
3182
+ class Animation extends Component {
3183
+ get mixer() {
3184
+ return this._mixer;
3185
+ }
3186
+ get action() {
3187
+ return this._action;
3188
+ }
3189
+ get actions() {
3190
+ return this._actions;
3191
+ }
3192
+ get progress() {
3193
+ return this._progress;
3194
+ }
3195
+ set progress(v) {
3196
+ if (this.playing) return;
3197
+ if (this._action) {
3198
+ const duration = this._action.getClip().duration;
3199
+ this._mixer.setTime(v * duration);
3200
+ }
3201
+ }
3202
+ onLoad() {
3203
+ this._mixer = new three.AnimationMixer(this.node);
3204
+ this._actions = this.node.animations.map((v)=>this._mixer.clipAction(v));
3205
+ }
3206
+ onDestroy() {
3207
+ this._mixer.stopAllAction();
3208
+ }
3209
+ update(dt) {
3210
+ if (this.playing) {
3211
+ this._mixer.update(dt);
3212
+ }
3213
+ if (this._action) {
3214
+ const duration = this._action.getClip().duration;
3215
+ this._progress = this._mixer.time % duration / duration;
3216
+ }
3217
+ }
3218
+ play(animName, state = {}) {
3219
+ let action = animName ? this._actions.find((v)=>v.getClip().name === animName) : this._actions[0];
3220
+ if (action) {
3221
+ if (state.clampWhenFinished !== undefined) action.clampWhenFinished = state.clampWhenFinished;
3222
+ if (state.zeroSlopeAtStart !== undefined) action.zeroSlopeAtStart = state.zeroSlopeAtStart;
3223
+ if (state.zeroSlopeAtEnd !== undefined) action.zeroSlopeAtEnd = state.zeroSlopeAtEnd;
3224
+ if (state.mode) action.setLoop(state.mode, state.repetitions);
3225
+ if (state.duration) action.setDuration(state.duration);
3226
+ if (this._action) {
3227
+ this._action.stop();
3228
+ }
3229
+ this._action = action.play();
3230
+ this.playing = true;
3231
+ }
3232
+ return this;
3233
+ }
3234
+ stop() {
3235
+ if (this._action) {
3236
+ this._action.stop();
3237
+ this._action = null;
3238
+ }
3239
+ this.playing = false;
3240
+ return this;
3241
+ }
3242
+ constructor(...args){
3243
+ super(...args);
3244
+ this._progress = 0;
3245
+ this.playing = false;
3246
+ }
3247
+ }
3248
+
3182
3249
  const vert_fullscreen = /*glsl*/ `
3183
3250
  varying vec2 vUv;
3184
3251
  void main() {
@@ -4336,7 +4403,7 @@ class ResourceManager {
4336
4403
  }
4337
4404
  });
4338
4405
  } else {
4339
- reject("ResourceManager.loadAsset: missing loader for " + url);
4406
+ reject("ResourceManager.loadAsset: missing loader for " + sel);
4340
4407
  }
4341
4408
  });
4342
4409
  }
@@ -4673,10 +4740,9 @@ class Viewer extends EventEmitter {
4673
4740
  const frameCallback = (time)=>{
4674
4741
  if (this._running) {
4675
4742
  this._frame(time * 0.001);
4676
- requestAnimationFrame(frameCallback);
4677
4743
  }
4678
4744
  };
4679
- requestAnimationFrame(frameCallback);
4745
+ this._renderer.setAnimationLoop(frameCallback);
4680
4746
  }
4681
4747
  return this;
4682
4748
  }
@@ -5619,6 +5685,9 @@ class DropFilePlugin extends Plugin {
5619
5685
  asset.userData.ext = ext;
5620
5686
  this._onLoad && this._onLoad(asset);
5621
5687
  };
5688
+ const errCallback = (err)=>{
5689
+ this._onError && this._onError(err);
5690
+ };
5622
5691
  if ([
5623
5692
  "fbx",
5624
5693
  "gltf",
@@ -5629,7 +5698,7 @@ class DropFilePlugin extends Plugin {
5629
5698
  ext,
5630
5699
  buffer: event.target.result,
5631
5700
  resourcePath: dir
5632
- }).then(loadCallback);
5701
+ }).then(loadCallback).catch(errCallback);
5633
5702
  }, false);
5634
5703
  reader.readAsArrayBuffer(file);
5635
5704
  } else {
@@ -5637,13 +5706,13 @@ class DropFilePlugin extends Plugin {
5637
5706
  this.viewer.loadAsset({
5638
5707
  ext,
5639
5708
  url: event.target.result
5640
- }).then(loadCallback);
5709
+ }).then(loadCallback).catch(errCallback);
5641
5710
  }, false);
5642
5711
  reader.readAsDataURL(file);
5643
5712
  }
5644
5713
  }
5645
5714
  }
5646
- constructor({ onLoad, extension = [
5715
+ constructor({ onLoad, onError, extension = [
5647
5716
  "glb",
5648
5717
  "gltf",
5649
5718
  "fbx",
@@ -5664,6 +5733,7 @@ class DropFilePlugin extends Plugin {
5664
5733
  }
5665
5734
  };
5666
5735
  this._onLoad = onLoad;
5736
+ this._onError = onError;
5667
5737
  this._extensions = Array.isArray(extension) ? extension : [
5668
5738
  extension
5669
5739
  ];
@@ -5716,6 +5786,7 @@ function getFilesFromItemList(items, onDone) {
5716
5786
  }
5717
5787
  }
5718
5788
 
5789
+ exports.Animation = Animation;
5719
5790
  exports.AnimationCurve = AnimationCurve;
5720
5791
  exports.Box = Box;
5721
5792
  exports.BoxProjectionPlugin = BoxProjectionPlugin;