三个J不识别OBJLoader

时间:2017-09-08 13:47:19

标签: javascript three.js

我正在尝试在三个j中加载一个3d模型,我看到了这个错误信息。网上没有信息......任何人都可以帮忙吗? 我验证了mtl和obj lib是在threejs之后和模型脚本之前的正确位置调用的。

这是代码

   'use strict';

    var scene6, camera6, renderer6, light, model, shipMtl, shipObj;

    function init() {
        scene6 = new THREE.Scene();
        camera6 = new THREE.PerspectiveCamera(35, 1, 1, 1000);
        camera6.position.z = 400;

        //LIGHTS
        light = new THREE.PointLight(0xffffff, 2, 0);
        light.position.set(200, 100, 300);
        scene6.add(light);

        renderer6 = new THREE.WebGLRenderer({ canvas: document.getElementById('model'), antialias: true });
        renderer6.setClearColor(0x000000);
        renderer6.setPixelRatio(window.devicePixelRatio);

        model = new THREE.Mesh(
            new THREE.BoxGeometry(100, 100, 100, 50),
            new THREE.MeshPhongMaterial({
                color: 0xffffff,
                wireframe: true
            })
        );
        scene6.add(model);

        //MODEL
        shipMtl = new THREE.MTLLoader();
        shipMtl.load('../models/spaceCraft1.mtl', function(materials) {
            materials.preload();
            shipObj = new THREE.OBJLoader();
            shipObj.setMaterials(materials);
            shipObj.load('../models/spaceCraft1.obj', function(object) {
                scene6.add(object);
                object.rotation.y += .01;
            });
        });

        animate6();
    }

    function animate6() {

        model.rotation.y += .01;
        model.rotation.x -= .01;

        requestAnimationFrame(animate6);
        renderer6.render(scene6, camera6);        
    }

    window.onload = init;

这是错误信息:

OBJLoader.js:530 Uncaught Error: Unexpected line: 'usemap _defaultMat'
    at THREE.OBJLoader.parse (OBJLoader.js:530)
    at OBJLoader.js:51
    at XMLHttpRequest.<anonymous> (three.js:30090)

提前谢谢。

1 个答案:

答案 0 :(得分:-1)

好的我找到了解决方案。

在OBJLoader.js文件中,我必须更换每个&#34; &#39;的事情&#39; &#34;用&#39; &#34;东西&#34; &#39;

感谢大家的关注。

干杯