Javascript JSON数据3JS ObjectLoader的第1行第1列出现意外字符
基本上,每当我尝试加载任何.obj文件时,都会出现以下错误Javascript JSON数据3JS ObjectLoader的第1行第1列出现意外字符,javascript,json,three.js,Javascript,Json,Three.js,基本上,每当我尝试加载任何.obj文件时,都会出现以下错误 THREE:ObjectLoader: Can't parse obj/weapon_4.obj. JSON.parse: unexpected character at line 1 column 1 of the JSON data 任何文件都会发生这种情况。没有我尝试过的obj文件。这是我试图加载的一个obj文件,但它不起作用。我将只发布前五行,因为错误表明意外字符位于第一行 # Exported from Wings 3D 1
THREE:ObjectLoader: Can't parse obj/weapon_4.obj. JSON.parse: unexpected character at line 1 column 1 of the JSON data
任何文件都会发生这种情况。没有我尝试过的obj文件。这是我试图加载的一个obj文件,但它不起作用。我将只发布前五行,因为错误表明意外字符位于第一行
# Exported from Wings 3D 1.5.3
mtllib Tent_Poles_01.mtl
o Mesh1
#63 vertices, 122 faces
v -1.31380400 1.1423300e-15 -1.30752000
... the rest is basically just vertices
我不知道obj文件有什么问题。在这一点上,我非常确定这与我的代码有关。这是我的main.js文件
const d = document;
const $ = d.querySelector.bind(d);
let [w, h] = [innerWidth-10, innerHeight-10];
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, w/h, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
const initSize = () => {
[w, h] = [innerWidth-10, innerHeight-10];
renderer.setSize(w, h);
camera.aspect = w/h;
camera.updateProjectionMatrix();
};
addEventListener("resize", initSize);
addEventListener("load", initSize);
d.body.appendChild(renderer.domElement);
const controls = new THREE.OrbitControls(camera, renderer.domElement);
const loader = new THREE.ObjectLoader();
loader.load(
"obj/weapon_4.obj",
(object) => {
scene.add(object); // Error
}
);
const ambientLight = new THREE.AmbientLight(0xFFFFFF, 0.2);
const directionLight = new THREE.DirectionalLight(0xFFFFFF, 10);
const spotLight = new THREE.SpotLight(0xFF45F6, 25);
directionLight.position.set(1, 1, 0);
spotLight.position.set(0, 2, 0);
scene.add(ambientLight);
scene.add(spotLight);
scene.add(directionLight);
camera.position.z = 3;
const update = () => {
// todo...
};
const render = () => {
renderer.render(scene, camera);
};
const GameLoop = () => {
requestAnimationFrame(GameLoop);
update();
render();
};
GameLoop();
如果有人能帮我加载obj文件那就太好了。我知道灯光很乱,我只是在胡闹。如有必要,我可以提供任何其他文件。提前感谢。加载程序希望对象为JSON对象/场景文件格式,但您的obj文件不是该格式 参考资料: 您需要更改文件或使用其他加载程序。您必须使用以下示例中演示的加载程序: 您使用了用于加载three.JSON格式的