@xviewer.js/core 1.0.0-alpha.54 → 1.0.0-alpha.56

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
@@ -1119,14 +1119,18 @@ class aEXRLoader extends aLoader {
1119
1119
  }
1120
1120
 
1121
1121
  class aFBXLoader extends aLoader {
1122
- load({ url, onLoad, onProgress, onError }) {
1122
+ load({ url, buffer, onLoad, onProgress, onError }) {
1123
1123
  const loadCallback = (node)=>{
1124
1124
  onLoad(aLoader._setUserData(node));
1125
1125
  };
1126
1126
  const loader = new FBXLoader(this.manager.loadingManager);
1127
1127
  loader.setPath(this.manager.path);
1128
1128
  loader.setResourcePath(this.manager.resourcePath);
1129
- loader.load(url, loadCallback, onProgress, onError);
1129
+ if (buffer) {
1130
+ loadCallback(loader.parse(buffer, this.manager.path));
1131
+ } else {
1132
+ loader.load(url, loadCallback, onProgress, onError);
1133
+ }
1130
1134
  }
1131
1135
  constructor(...args){
1132
1136
  super(...args);
@@ -1137,7 +1141,7 @@ class aFBXLoader extends aLoader {
1137
1141
  }
1138
1142
 
1139
1143
  class aGLTFLoader extends aLoader {
1140
- load({ url, onLoad, onProgress, onError }) {
1144
+ load({ url, buffer, onLoad, onProgress, onError }) {
1141
1145
  const loadCallback = (gltf)=>{
1142
1146
  const node = gltf.scene;
1143
1147
  if (gltf.animations) node.animations = gltf.animations;
@@ -1150,7 +1154,11 @@ class aGLTFLoader extends aLoader {
1150
1154
  dracoLoader.setDecoderPath(this.manager.dracoPath);
1151
1155
  gltfLoader.setDRACOLoader(dracoLoader);
1152
1156
  gltfLoader.setMeshoptDecoder(MeshoptDecoder);
1153
- gltfLoader.load(url, loadCallback, onProgress, onError);
1157
+ if (buffer) {
1158
+ gltfLoader.parse(buffer, this.manager.path, loadCallback, onError);
1159
+ } else {
1160
+ gltfLoader.load(url, loadCallback, onProgress, onError);
1161
+ }
1154
1162
  }
1155
1163
  constructor(...args){
1156
1164
  super(...args);
@@ -1163,13 +1171,13 @@ class aGLTFLoader extends aLoader {
1163
1171
 
1164
1172
  class aHDRLoader extends aLoader {
1165
1173
  load({ url, onLoad, onProgress, onError, texSettings }) {
1166
- texSettings = Object.assign({
1174
+ const settings = Object.assign({
1167
1175
  mapping: EquirectangularReflectionMapping
1168
1176
  }, texSettings);
1169
1177
  const loader = new RGBELoader(this.manager.loadingManager);
1170
1178
  loader.setPath(this.manager.path);
1171
1179
  loader.setResourcePath(this.manager.resourcePath);
1172
- loader.load(url, (tex)=>onLoad(Object.assign(tex, texSettings)), onProgress, onError);
1180
+ loader.load(url, (tex)=>onLoad(Object.assign(tex, settings)), onProgress, onError);
1173
1181
  }
1174
1182
  constructor(...args){
1175
1183
  super(...args);
@@ -4241,7 +4249,7 @@ class ResourceManager {
4241
4249
  static extension(path) {
4242
4250
  let str = path.split(".");
4243
4251
  if (str.length > 1) {
4244
- return str.pop();
4252
+ return str.pop().toLowerCase();
4245
4253
  }
4246
4254
  return "";
4247
4255
  }
@@ -4253,28 +4261,6 @@ class ResourceManager {
4253
4261
  let str = path.split("/").pop();
4254
4262
  return ext ? str.replace("." + ext, "") : str;
4255
4263
  }
4256
- static _parseURL(uri) {
4257
- let url = "";
4258
- let file = null;
4259
- let ext = "";
4260
- if (typeof File !== "undefined" && uri instanceof File) {
4261
- url = uri.name;
4262
- ext = ResourceManager.extension(url);
4263
- file = uri;
4264
- } else if (typeof uri === "object") {
4265
- url = uri.mainFile.name;
4266
- ext = ResourceManager.extension(url);
4267
- file = uri;
4268
- } else {
4269
- url += uri;
4270
- ext = ResourceManager.extension(url);
4271
- }
4272
- return {
4273
- url,
4274
- file,
4275
- ext
4276
- };
4277
- }
4278
4264
  static _getTextureKey(url, settings) {
4279
4265
  let keys = [
4280
4266
  url
@@ -4301,17 +4287,20 @@ class ResourceManager {
4301
4287
  this._caches.clear();
4302
4288
  this._loaders.clear();
4303
4289
  }
4290
+ getLoader(ext) {
4291
+ return this._loaders.get(ext);
4292
+ }
4304
4293
  addLoader(Loader) {
4305
4294
  let loader = new Loader(this);
4306
4295
  for (let ext of loader.extension){
4307
4296
  this._loaders.set(ext, loader);
4308
4297
  }
4309
4298
  }
4310
- loadAsset({ url, ext, onProgress, ...props }) {
4299
+ loadAsset({ url, buffer, ext, onProgress, ...props }) {
4311
4300
  return new Promise((resolve, reject)=>{
4312
- const info = ResourceManager._parseURL(url);
4301
+ const ext_ = ResourceManager.extension(url);
4313
4302
  const texSettings = ResourceManager._splitTextureSettings(props);
4314
- const key = ResourceManager._getTextureKey(info.url, texSettings);
4303
+ const key = ResourceManager._getTextureKey(url, texSettings);
4315
4304
  let result = this._caches.get(key);
4316
4305
  if (result) {
4317
4306
  resolve(result);
@@ -4320,10 +4309,11 @@ class ResourceManager {
4320
4309
  this._caches.set(key, file);
4321
4310
  resolve(file);
4322
4311
  };
4323
- let sel = ext || info.ext;
4312
+ const sel = ext || ext_;
4324
4313
  if (this._loaders.has(sel)) {
4325
4314
  this._loaders.get(sel).load({
4326
- url: info.url,
4315
+ url,
4316
+ buffer,
4327
4317
  texSettings,
4328
4318
  onProgress,
4329
4319
  onLoad,
@@ -4332,7 +4322,7 @@ class ResourceManager {
4332
4322
  }
4333
4323
  });
4334
4324
  } else {
4335
- reject("ResourceManager.loadAsset: missing loader for " + ext);
4325
+ reject("ResourceManager.loadAsset: missing loader for " + url);
4336
4326
  }
4337
4327
  }
4338
4328
  });
@@ -4609,6 +4599,15 @@ class Viewer extends EventEmitter {
4609
4599
  set targetFrameRate(v) {
4610
4600
  this._targetFrameRate = Math.max(0.001, v);
4611
4601
  }
4602
+ get loadingManager() {
4603
+ return this._loadingManager;
4604
+ }
4605
+ get resourceManager() {
4606
+ return this._resourceManager;
4607
+ }
4608
+ get taskManager() {
4609
+ return this._taskManager;
4610
+ }
4612
4611
  destroy() {
4613
4612
  this.stop();
4614
4613
  this._renderer.dispose();
@@ -4735,24 +4734,12 @@ class Viewer extends EventEmitter {
4735
4734
  loadAsset(props) {
4736
4735
  return this._resourceManager.loadAsset(props);
4737
4736
  }
4737
+ getLoader(ext) {
4738
+ return this._resourceManager.getLoader(ext);
4739
+ }
4738
4740
  addLoader(Loader) {
4739
4741
  this._resourceManager.addLoader(Loader);
4740
4742
  }
4741
- async load({ url, ext, onProgress, castShadow = false, receiveShadow = false, ...props }) {
4742
- const node = await this.loadAsset({
4743
- url,
4744
- ext,
4745
- onProgress
4746
- });
4747
- if (castShadow || receiveShadow) {
4748
- node.userData.meshData.meshes.forEach((v)=>{
4749
- v.castShadow = castShadow;
4750
- v.receiveShadow = receiveShadow;
4751
- });
4752
- }
4753
- this.addNode(node, props);
4754
- return node;
4755
- }
4756
4743
  timeline(target) {
4757
4744
  return this._tweenManager.timeline(target);
4758
4745
  }
@@ -4793,6 +4780,9 @@ class Viewer extends EventEmitter {
4793
4780
  removeComponent(node, component) {
4794
4781
  return this._componentManager.removeComponent(node, component);
4795
4782
  }
4783
+ addTask(task) {
4784
+ this._taskManager.add(task);
4785
+ }
4796
4786
  addNode(object, { args, debug, scale, position, rotation, layer, shadowArgs, makeDefault, component, parent = this._scene, ...props } = {}) {
4797
4787
  let node = null;
4798
4788
  let ins = getClassInstance(object, args);
@@ -4971,7 +4961,7 @@ class Viewer extends EventEmitter {
4971
4961
  this._renderer.shadowMap.enabled = !!shadows;
4972
4962
  this._renderer.shadowMap.type = typeof shadows === "boolean" ? PCFSoftShadowMap : shadows;
4973
4963
  this._renderer.info.autoReset = false;
4974
- const loadingManager = new LoadingManager(loader.onLoad, loader.onProgress, loader.onError);
4964
+ const loadingManager = this._loadingManager = new LoadingManager(loader.onLoad, loader.onProgress, loader.onError);
4975
4965
  this._resourceManager = new ResourceManager({
4976
4966
  path,
4977
4967
  resourcePath,
@@ -5575,5 +5565,5 @@ class PerformanceMonitorPlugin extends Plugin {
5575
5565
  }
5576
5566
  }
5577
5567
 
5578
- export { AnimationCurve, Box, BoxProjectionPlugin, CinestationBlendDefinition, CinestationBrain, Component, DebugPlugin, DeviceInput, Easing, EnvironmentPlugin, EventEmitter, FInterpConstantTo, FInterpTo, FreelookVirtualCamera, Logger, ObjectInstance, Orientation, PerformanceMonitorPlugin, Perlin, Plane, Plugin, PropertyManager, QInterpConstantTo, QInterpTo, Quat_AngularDistance, Quat_Equals, Quat_exponentialDamp, Quat_quarticDamp, Quat_smoothDamp, Reflector, ReflectorMaterial, Sphere, SystemInfo, Tween, TweenChain, TweenManager, VInterpConstantTo, VInterpTo, Vec3_smoothDamp, Vector3_NEG_ONE, Vector3_ONE, Vector3_RIGHT, Vector3_UNIT_X, Vector3_UNIT_Y, Vector3_UNIT_Z, Vector3_UP, Vector3_ZERO, Viewer, VirtualCamera, aEXRLoader, aFBXLoader, aGLTFLoader, aHDRLoader, aJSONLoader, aLoader, aTextureLoader, exponentialDamp, frag_BoxfilterBlur, frag_cubeMapToPanorama, frag_panoramaToCubeMap, getClassInstance, getShaderMaterial, mixin, property, quarticDamp, smoothDamp, vert_fullscreen };
5568
+ export { AnimationCurve, Box, BoxProjectionPlugin, CinestationBlendDefinition, CinestationBrain, Component, DebugPlugin, DeviceInput, Easing, EnvironmentPlugin, EventEmitter, FInterpConstantTo, FInterpTo, FreelookVirtualCamera, Logger, ObjectInstance, Orientation, PerformanceMonitorPlugin, Perlin, Plane, Plugin, PropertyManager, QInterpConstantTo, QInterpTo, Quat_AngularDistance, Quat_Equals, Quat_exponentialDamp, Quat_quarticDamp, Quat_smoothDamp, Reflector, ReflectorMaterial, ResourceManager, Sphere, SystemInfo, Tween, TweenChain, TweenManager, VInterpConstantTo, VInterpTo, Vec3_smoothDamp, Vector3_NEG_ONE, Vector3_ONE, Vector3_RIGHT, Vector3_UNIT_X, Vector3_UNIT_Y, Vector3_UNIT_Z, Vector3_UP, Vector3_ZERO, Viewer, VirtualCamera, aEXRLoader, aFBXLoader, aGLTFLoader, aHDRLoader, aJSONLoader, aLoader, aTextureLoader, exponentialDamp, frag_BoxfilterBlur, frag_cubeMapToPanorama, frag_panoramaToCubeMap, getClassInstance, getShaderMaterial, mixin, property, quarticDamp, smoothDamp, vert_fullscreen };
5579
5569
  //# sourceMappingURL=module.js.map