Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 views
in Technique[技术] by (71.8m points)

javascript - Three Js do not recognise OBJLoader

I'm trying to load a 3d Model in Three js and I'm seeing this error message. No info in the web... Anyone can help please? I verified the mtl and obj lib are called on the right place just after threejs and before the model script.

This is the code

   '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;

And this the error message:

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)

Thank you in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ok So I found the solution.

On OBJLoader.js file I had to replace every " 'thing' " with ' "thing" '.

Thank s to everyone for your attention.

Cheers


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...