@xviewer.js/core 1.0.4-alpha.2 → 1.0.4-alpha.4

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
@@ -165,7 +165,6 @@ function getClassInstance(constructor, args = []) {
165
165
 
166
166
  class Loader {
167
167
  static _setUserData(node) {
168
- const keys = Loader._texKeys;
169
168
  const meshes = [];
170
169
  const textures = {};
171
170
  const materials = {};
@@ -183,7 +182,7 @@ class Loader {
183
182
  queue.push(...object.children);
184
183
  }
185
184
  Object.values(materials).forEach((mat)=>{
186
- keys.forEach((k)=>{
185
+ Loader._texKeys.forEach((k)=>{
187
186
  let tex = mat[k];
188
187
  if (tex) {
189
188
  textures[tex.uuid] = tex;
@@ -244,13 +243,10 @@ class FBXLoader extends Loader {
244
243
  loader.manager = manager;
245
244
  loader.setPath(path);
246
245
  loader.setResourcePath(resourcePath);
247
- const loadCallback = (node)=>{
248
- onLoad(Loader._setUserData(node));
249
- };
250
246
  if (buffer) {
251
- loadCallback(loader.parse(buffer, resourcePath));
247
+ onLoad(loader.parse(buffer, resourcePath));
252
248
  } else {
253
- loader.load(url, loadCallback, onProgress, onError);
249
+ loader.load(url, onLoad, onProgress, onError);
254
250
  }
255
251
  }
256
252
  constructor(...args){
@@ -277,15 +273,10 @@ class GLTFLoader extends Loader {
277
273
  loader.manager = manager;
278
274
  loader.setPath(path);
279
275
  loader.setResourcePath(resourcePath);
280
- const loadCallback = (gltf)=>{
281
- const node = gltf.scene;
282
- node.animations.push(...gltf.animations);
283
- onLoad(Loader._setUserData(node));
284
- };
285
276
  if (buffer) {
286
- loader.parse(buffer, resourcePath, loadCallback, onError);
277
+ loader.parse(buffer, resourcePath, onLoad, onError);
287
278
  } else {
288
- loader.load(url, loadCallback, onProgress, onError);
279
+ loader.load(url, onLoad, onProgress, onError);
289
280
  }
290
281
  }
291
282
  constructor(...args){
@@ -379,15 +370,10 @@ class BINLoader extends Loader {
379
370
  loader.manager = manager;
380
371
  loader.setPath(path);
381
372
  loader.setResourcePath(resourcePath);
382
- const loadCallback = (gltf)=>{
383
- const node = gltf.scene;
384
- node.animations.push(...gltf.animations);
385
- onLoad(Loader._setUserData(node));
386
- };
387
373
  if (buffer) {
388
- loader.parse(buffer, resourcePath, loadCallback, onError);
374
+ loader.parse(buffer, resourcePath, onLoad, onError);
389
375
  } else {
390
- loader.load(url, loadCallback, onProgress, onError);
376
+ loader.load(url, onLoad, onProgress, onError);
391
377
  }
392
378
  }
393
379
  constructor(...args){
@@ -2245,8 +2231,7 @@ class ComponentScheduler {
2245
2231
  if (comp.onEnable) {
2246
2232
  comp.onEnable();
2247
2233
  }
2248
- if (typeof comp.start === "function" && !comp.flags.isStartCalled) {
2249
- comp.flags.isStartCalled = true;
2234
+ if (typeof comp.start === "function") {
2250
2235
  this.startInvoker.add(comp);
2251
2236
  }
2252
2237
  if (typeof comp.update === "function") {
@@ -2287,11 +2272,22 @@ class ComponentScheduler {
2287
2272
  }
2288
2273
  }
2289
2274
  constructor(){
2290
- this.startInvoker = new InvokerOneCall((comp)=>comp.start());
2291
- this.updateInvoker = new Invoker((comp, dt)=>comp.update(dt));
2292
- this.lastUpdateInvoker = new Invoker((comp, dt)=>comp.lastUpdate(dt));
2293
- this.renderInvoker = new Invoker((comp, dt)=>comp.render(dt));
2294
- this.resizeInvoker = new Invoker((comp, width, height)=>comp.resize(width, height));
2275
+ this.startInvoker = new InvokerOneCall((comp)=>{
2276
+ comp.start();
2277
+ comp.start = undefined;
2278
+ });
2279
+ this.updateInvoker = new Invoker((comp, dt)=>{
2280
+ !comp.start && comp.update(dt);
2281
+ });
2282
+ this.lastUpdateInvoker = new Invoker((comp, dt)=>{
2283
+ !comp.start && comp.lastUpdate(dt);
2284
+ });
2285
+ this.renderInvoker = new Invoker((comp, dt)=>{
2286
+ !comp.start && comp.render(dt);
2287
+ });
2288
+ this.resizeInvoker = new Invoker((comp, width, height)=>{
2289
+ !comp.start && comp.resize(width, height);
2290
+ });
2295
2291
  }
2296
2292
  }
2297
2293
 
@@ -2476,12 +2472,12 @@ ComponentManager._infoMap = new Map();
2476
2472
 
2477
2473
  class Renderer extends Component {
2478
2474
  render(dt) {
2479
- const { renderer, scene, camera } = this.context;
2475
+ const { renderer, scene, camera } = this.viewer;
2480
2476
  renderer.setRenderTarget(null);
2481
2477
  renderer.render(scene, camera);
2482
2478
  }
2483
2479
  resize(width, height) {
2484
- const { renderer } = this.context;
2480
+ const { renderer } = this.viewer;
2485
2481
  renderer.setSize(width, height);
2486
2482
  }
2487
2483
  constructor(...args){
@@ -4411,19 +4407,15 @@ class ResourceManager {
4411
4407
  }
4412
4408
  return loader;
4413
4409
  }
4414
- loadAsset({ url, buffer, ext, path, resourcePath, dracoPath, manager, onProgress, ...props }) {
4410
+ loadAsset({ url, ext, onProgress, ...props }) {
4415
4411
  return new Promise((resolve, reject)=>{
4416
4412
  const sel = ext || url && ResourceManager.extension(url) || "";
4417
4413
  const texSettings = ResourceManager._splitTextureSettings(props);
4418
4414
  if (this._loaders.has(sel)) {
4419
4415
  this._loaders.get(sel).load({
4420
4416
  url,
4421
- buffer,
4422
4417
  texSettings,
4423
- path,
4424
- resourcePath,
4425
- dracoPath,
4426
- manager,
4418
+ ...props,
4427
4419
  onProgress,
4428
4420
  onLoad: resolve,
4429
4421
  onError: (err)=>{
@@ -4880,6 +4872,9 @@ class Viewer extends EventEmitter {
4880
4872
  clearColor(renderTarget, color, alpha) {
4881
4873
  Viewer.ClearColor(this._renderer, renderTarget, color, alpha);
4882
4874
  }
4875
+ stash(renderTarget, callback, clearColor, clearAlpha) {
4876
+ Viewer.Stash(this._renderer, renderTarget, callback, clearColor, clearAlpha);
4877
+ }
4883
4878
  blur(blurLevel, shadingScale, inputBuffer, tempBuffer, outputBuffer, fixedOutput) {
4884
4879
  Viewer.Blur(this._renderer, blurLevel, shadingScale, inputBuffer, tempBuffer, outputBuffer, fixedOutput);
4885
4880
  }
@@ -4975,7 +4970,7 @@ class Viewer extends EventEmitter {
4975
4970
  renderer.autoClear = true;
4976
4971
  renderer.setRenderTarget(renderTarget);
4977
4972
  clearColor !== undefined && renderer.setClearColor(clearColor, clearAlpha);
4978
- callback && callback();
4973
+ callback && callback(renderer);
4979
4974
  renderer.autoClear = autoClear;
4980
4975
  renderer.setRenderTarget(RT);
4981
4976
  clearColor !== undefined && renderer.setClearColor(color, alpha);