三个js不认识OBJLoader [英] Three Js do not recognise OBJLoader

查看:34
本文介绍了三个js不认识OBJLoader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Three js 中加载 3d 模型,但看到此错误消息.网络上没有任何信息...任何人都可以帮忙吗?我验证了 mtl 和 obj lib 在 Threejs 之后和模型脚本之前的正确位置被调用.

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.

这是代码

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

提前致谢.

推荐答案

好的,我找到了解决方案.

Ok So I found the solution.

在 OBJLoader.js 文件中,我不得不将每个'东西'"替换为'东西"'.

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

感谢大家的关注.

干杯

这篇关于三个js不认识OBJLoader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆