Three.js从输入文件本地加载FBX和材料

时间:2018-12-17 10:40:36

标签: three.js

几天以来,我试图用输入文件本地的材料加载.fbx文件,但没有成功。 我发现此代码可与collada文件一起使用,我已将其更改为可与.fbx一起使用,但没什么...

$("#campoFile3dNascosto").change(function (e) {
    var files = e.currentTarget.files;
    var dae_path;

    var extraFiles = {}, file;
    for (var i = 0; i < files.length; i++) {
        file = files[i];
        extraFiles[file.name] = file;

        //Filename ends in .dae/.DAE
        if (files[i].name.match(/\w*.dae\b/i)) {
            dae_path = files[i].name;
        }
    }

    const manager = new THREE.LoadingManager();
    manager.setURLModifier(function (url, path) {

        url = url.split('/');
        url = url[url.length - 1];

        if (extraFiles[url] !== undefined) {

            var blobURL = URL.createObjectURL(extraFiles[url]);
            console.log("blob: "+blobURL); //Blob location created from files selected from file input
            return blobURL;

        }
        return url;
    });


    var loader = new THREE.FBXLoader(manager);
    loader.load(dae_path, function (object) {
       object.traverse(function (child) {
            if (child.isMesh) {
                child.castShadow = true;
                child.receiveShadow = true;
            }
        });
    });

});

我该怎么做?

0 个答案:

没有答案