@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/main.js CHANGED
@@ -1121,14 +1121,18 @@ class aEXRLoader extends aLoader {
1121
1121
  }
1122
1122
 
1123
1123
  class aFBXLoader extends aLoader {
1124
- load({ url, onLoad, onProgress, onError }) {
1124
+ load({ url, buffer, onLoad, onProgress, onError }) {
1125
1125
  const loadCallback = (node)=>{
1126
1126
  onLoad(aLoader._setUserData(node));
1127
1127
  };
1128
1128
  const loader = new FBXLoader_js.FBXLoader(this.manager.loadingManager);
1129
1129
  loader.setPath(this.manager.path);
1130
1130
  loader.setResourcePath(this.manager.resourcePath);
1131
- loader.load(url, loadCallback, onProgress, onError);
1131
+ if (buffer) {
1132
+ loadCallback(loader.parse(buffer, this.manager.path));
1133
+ } else {
1134
+ loader.load(url, loadCallback, onProgress, onError);
1135
+ }
1132
1136
  }
1133
1137
  constructor(...args){
1134
1138
  super(...args);
@@ -1139,7 +1143,7 @@ class aFBXLoader extends aLoader {
1139
1143
  }
1140
1144
 
1141
1145
  class aGLTFLoader extends aLoader {
1142
- load({ url, onLoad, onProgress, onError }) {
1146
+ load({ url, buffer, onLoad, onProgress, onError }) {
1143
1147
  const loadCallback = (gltf)=>{
1144
1148
  const node = gltf.scene;
1145
1149
  if (gltf.animations) node.animations = gltf.animations;
@@ -1152,7 +1156,11 @@ class aGLTFLoader extends aLoader {
1152
1156
  dracoLoader.setDecoderPath(this.manager.dracoPath);
1153
1157
  gltfLoader.setDRACOLoader(dracoLoader);
1154
1158
  gltfLoader.setMeshoptDecoder(meshopt_decoder_module_js.MeshoptDecoder);
1155
- gltfLoader.load(url, loadCallback, onProgress, onError);
1159
+ if (buffer) {
1160
+ gltfLoader.parse(buffer, this.manager.path, loadCallback, onError);
1161
+ } else {
1162
+ gltfLoader.load(url, loadCallback, onProgress, onError);
1163
+ }
1156
1164
  }
1157
1165
  constructor(...args){
1158
1166
  super(...args);
@@ -1165,13 +1173,13 @@ class aGLTFLoader extends aLoader {
1165
1173
 
1166
1174
  class aHDRLoader extends aLoader {
1167
1175
  load({ url, onLoad, onProgress, onError, texSettings }) {
1168
- texSettings = Object.assign({
1176
+ const settings = Object.assign({
1169
1177
  mapping: three.EquirectangularReflectionMapping
1170
1178
  }, texSettings);
1171
1179
  const loader = new RGBELoader_js.RGBELoader(this.manager.loadingManager);
1172
1180
  loader.setPath(this.manager.path);
1173
1181
  loader.setResourcePath(this.manager.resourcePath);
1174
- loader.load(url, (tex)=>onLoad(Object.assign(tex, texSettings)), onProgress, onError);
1182
+ loader.load(url, (tex)=>onLoad(Object.assign(tex, settings)), onProgress, onError);
1175
1183
  }
1176
1184
  constructor(...args){
1177
1185
  super(...args);
@@ -4243,7 +4251,7 @@ class ResourceManager {
4243
4251
  static extension(path) {
4244
4252
  let str = path.split(".");
4245
4253
  if (str.length > 1) {
4246
- return str.pop();
4254
+ return str.pop().toLowerCase();
4247
4255
  }
4248
4256
  return "";
4249
4257
  }
@@ -4255,28 +4263,6 @@ class ResourceManager {
4255
4263
  let str = path.split("/").pop();
4256
4264
  return ext ? str.replace("." + ext, "") : str;
4257
4265
  }
4258
- static _parseURL(uri) {
4259
- let url = "";
4260
- let file = null;
4261
- let ext = "";
4262
- if (typeof File !== "undefined" && uri instanceof File) {
4263
- url = uri.name;
4264
- ext = ResourceManager.extension(url);
4265
- file = uri;
4266
- } else if (typeof uri === "object") {
4267
- url = uri.mainFile.name;
4268
- ext = ResourceManager.extension(url);
4269
- file = uri;
4270
- } else {
4271
- url += uri;
4272
- ext = ResourceManager.extension(url);
4273
- }
4274
- return {
4275
- url,
4276
- file,
4277
- ext
4278
- };
4279
- }
4280
4266
  static _getTextureKey(url, settings) {
4281
4267
  let keys = [
4282
4268
  url
@@ -4303,17 +4289,20 @@ class ResourceManager {
4303
4289
  this._caches.clear();
4304
4290
  this._loaders.clear();
4305
4291
  }
4292
+ getLoader(ext) {
4293
+ return this._loaders.get(ext);
4294
+ }
4306
4295
  addLoader(Loader) {
4307
4296
  let loader = new Loader(this);
4308
4297
  for (let ext of loader.extension){
4309
4298
  this._loaders.set(ext, loader);
4310
4299
  }
4311
4300
  }
4312
- loadAsset({ url, ext, onProgress, ...props }) {
4301
+ loadAsset({ url, buffer, ext, onProgress, ...props }) {
4313
4302
  return new Promise((resolve, reject)=>{
4314
- const info = ResourceManager._parseURL(url);
4303
+ const ext_ = ResourceManager.extension(url);
4315
4304
  const texSettings = ResourceManager._splitTextureSettings(props);
4316
- const key = ResourceManager._getTextureKey(info.url, texSettings);
4305
+ const key = ResourceManager._getTextureKey(url, texSettings);
4317
4306
  let result = this._caches.get(key);
4318
4307
  if (result) {
4319
4308
  resolve(result);
@@ -4322,10 +4311,11 @@ class ResourceManager {
4322
4311
  this._caches.set(key, file);
4323
4312
  resolve(file);
4324
4313
  };
4325
- let sel = ext || info.ext;
4314
+ const sel = ext || ext_;
4326
4315
  if (this._loaders.has(sel)) {
4327
4316
  this._loaders.get(sel).load({
4328
- url: info.url,
4317
+ url,
4318
+ buffer,
4329
4319
  texSettings,
4330
4320
  onProgress,
4331
4321
  onLoad,
@@ -4334,7 +4324,7 @@ class ResourceManager {
4334
4324
  }
4335
4325
  });
4336
4326
  } else {
4337
- reject("ResourceManager.loadAsset: missing loader for " + ext);
4327
+ reject("ResourceManager.loadAsset: missing loader for " + url);
4338
4328
  }
4339
4329
  }
4340
4330
  });
@@ -4611,6 +4601,15 @@ class Viewer extends EventEmitter {
4611
4601
  set targetFrameRate(v) {
4612
4602
  this._targetFrameRate = Math.max(0.001, v);
4613
4603
  }
4604
+ get loadingManager() {
4605
+ return this._loadingManager;
4606
+ }
4607
+ get resourceManager() {
4608
+ return this._resourceManager;
4609
+ }
4610
+ get taskManager() {
4611
+ return this._taskManager;
4612
+ }
4614
4613
  destroy() {
4615
4614
  this.stop();
4616
4615
  this._renderer.dispose();
@@ -4737,24 +4736,12 @@ class Viewer extends EventEmitter {
4737
4736
  loadAsset(props) {
4738
4737
  return this._resourceManager.loadAsset(props);
4739
4738
  }
4739
+ getLoader(ext) {
4740
+ return this._resourceManager.getLoader(ext);
4741
+ }
4740
4742
  addLoader(Loader) {
4741
4743
  this._resourceManager.addLoader(Loader);
4742
4744
  }
4743
- async load({ url, ext, onProgress, castShadow = false, receiveShadow = false, ...props }) {
4744
- const node = await this.loadAsset({
4745
- url,
4746
- ext,
4747
- onProgress
4748
- });
4749
- if (castShadow || receiveShadow) {
4750
- node.userData.meshData.meshes.forEach((v)=>{
4751
- v.castShadow = castShadow;
4752
- v.receiveShadow = receiveShadow;
4753
- });
4754
- }
4755
- this.addNode(node, props);
4756
- return node;
4757
- }
4758
4745
  timeline(target) {
4759
4746
  return this._tweenManager.timeline(target);
4760
4747
  }
@@ -4795,6 +4782,9 @@ class Viewer extends EventEmitter {
4795
4782
  removeComponent(node, component) {
4796
4783
  return this._componentManager.removeComponent(node, component);
4797
4784
  }
4785
+ addTask(task) {
4786
+ this._taskManager.add(task);
4787
+ }
4798
4788
  addNode(object, { args, debug, scale, position, rotation, layer, shadowArgs, makeDefault, component, parent = this._scene, ...props } = {}) {
4799
4789
  let node = null;
4800
4790
  let ins = getClassInstance(object, args);
@@ -4973,7 +4963,7 @@ class Viewer extends EventEmitter {
4973
4963
  this._renderer.shadowMap.enabled = !!shadows;
4974
4964
  this._renderer.shadowMap.type = typeof shadows === "boolean" ? three.PCFSoftShadowMap : shadows;
4975
4965
  this._renderer.info.autoReset = false;
4976
- const loadingManager = new three.LoadingManager(loader.onLoad, loader.onProgress, loader.onError);
4966
+ const loadingManager = this._loadingManager = new three.LoadingManager(loader.onLoad, loader.onProgress, loader.onError);
4977
4967
  this._resourceManager = new ResourceManager({
4978
4968
  path,
4979
4969
  resourcePath,
@@ -5607,6 +5597,7 @@ exports.Quat_quarticDamp = Quat_quarticDamp;
5607
5597
  exports.Quat_smoothDamp = Quat_smoothDamp;
5608
5598
  exports.Reflector = Reflector;
5609
5599
  exports.ReflectorMaterial = ReflectorMaterial;
5600
+ exports.ResourceManager = ResourceManager;
5610
5601
  exports.Sphere = Sphere;
5611
5602
  exports.SystemInfo = SystemInfo;
5612
5603
  exports.Tween = Tween;