Coder Social home page Coder Social logo

Comments (10)

yandeu avatar yandeu commented on June 10, 2024

Thanks for reporting. I will have a closer look once in my office.

from enable3d.

yandeu avatar yandeu commented on June 10, 2024

I could not reproduce this error. The code below works fine.

class MainScene extends Scene3D {
  async preload() {
    await this.load.preload('man', '/assets/box_man.glb')
  }

  async create() {
    this.warpSpeed()

    this.load.gltf('man').then(gltf => {
      const child = gltf.scene.children[0]
      child.position.setX(-1)
      this.scene.add(child)
    })

    this.load.gltf('man').then(gltf => {
      const child = gltf.scene.children[0]
      child.position.setX(1)
      this.scene.add(child)
    })
  }
}

from enable3d.

PtrBld avatar PtrBld commented on June 10, 2024

Hi, sorry this is not what I meant. See example code below:

Working:

this.third.load.preload('ground', 'assets/ground.json');
this.third.load.preload('robot', 'assets/robot.glb');

this.third.load.object('ground').then((object) => {
  //anything
});

Not working:

this.third.load.preload('robot', 'assets/robot.glb');
this.third.load.preload('ground', 'assets/ground.json');

this.third.load.object('ground').then((object) => {
  //anything
});

Error message:
THREE:ObjectLoader: Can't parse assets/OBJ/ground.json. Unexpected token 'o', "[object ArrayBuffer]" is not valid JSON

As I said this is because line 66 in loaders.ts the responsetype is set to 'arraybuffer' for all files that are preloaded afterwards (in this case after robot.glb).

from enable3d.

yandeu avatar yandeu commented on June 10, 2024

I see. I guess this would fix it?

public async preload(key: string, url: string) {
  this.cache.add(key, url)

  return new Promise(resolve => {
    const isModel = /\.fbx$|\.glb$|\.gltf$/.test(url)
    const isTexture = /\.jpe?g$|\.png$/.test(url)

    if (isTexture) {
      this.textureLoader.load(url, texture => {
        return resolve(texture)
      })
    } else {
      if (isModel) this.fileLoader.setResponseType('arraybuffer')
+     else this.fileLoader.setResponseType('undefined')
      this.fileLoader.load(url, file => {
        return resolve(file)
      })
    }
  })
}

from enable3d.

PtrBld avatar PtrBld commented on June 10, 2024

Yes, that should do it. However, I think undefined without quotations would be better.

from enable3d.

yandeu avatar yandeu commented on June 10, 2024

The responseType can be undefined or string, but setResponseType only takes a string.
See https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/three/src/loaders/FileLoader.d.ts

from enable3d.

PtrBld avatar PtrBld commented on June 10, 2024

True. Thanks for your help!

from enable3d.

psociety avatar psociety commented on June 10, 2024

This also seems to happen if you use load twice for the same fbx:

let object;
const key = 'assets/fbx/Male.fbx'

object = await this.third.load.fbx(key);
object = await this.third.load.fbx(key);

It cries with a:

three.module.js:43861 Uncaught (in promise) TypeError: url.lastIndexOf is not a function
    at LoaderUtils.extractUrlBase (three.module.js:43861:1)
    at FBXLoader.load (FBXLoader.js:79:51)
    at loaders.js:157:1
    at new Promise (<anonymous>)
    at Loaders.fbx (loaders.js:156:1)

enable3d v0.25.4
Phaser v3.55.2 (WebGL | Web Audio)

from enable3d.

yandeu avatar yandeu commented on June 10, 2024

Try to preload your fbx file first.

from enable3d.

psociety avatar psociety commented on June 10, 2024

I cannot preload it, because the file to be loaded is dynamic (the name i set was an example).
Ex: multiplayer with 50 different avatars, not going to preload all of them.

This is my workaround:

// enable3d has a bug where FBXs can't be loaded more than once
  // as they are saved as ArrayBuffers on cache
async loadFBX (key: string) {
    if (this.currentScene.third.cache.get(key)) {
        return await this.currentScene.third.load._fbxLoader.parse(this.currentScene.third.cache.get(key));    
    }
    return await this.currentScene.third.load.fbx(key);
  }

from enable3d.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.