Three.js SceneExporter getting Uncaught Syntax error

喜欢而已 提交于 2019-12-12 02:05:11

问题


So I am trying to export a three.js scene using the SceneExporter, I am just doing this

var output = new THREE.SceneExporter().parse(scope.renderingEngine.scene);

When doing this, I get an error

Uncaught SyntaxError: Unexpected token u

Which occurs at line 750 of SceneExporter.js (which is the line where the JSON gets parsed; new THREE.SceneExporter().parse(scope.renderingEngine.scene);)

I don't have anything fancy going on in the scene, just a bunch of geometries. I even tried a scene with no textures in it and still got this error.

Now, if I change that line to simply return the output then JSON.stringify(output) and save this file, the file's JSON does not validate. I get the following error

Parse error on line 1:
"{    \n\t\"metadat
^
Expecting '{', '['

And here is line 1-10 of the JSON file

"{
    \n\t\"metadata\": {
        \n\t\t\"formatVersion\": 3.2,
        \n\t\t\"type\"\t\t: \"scene\",
        \n\t\t\"generatedBy\"\t: \"SceneExporter\",
        \n\t\t\"objects\": 153,
        \n\t\t\"geometries\": 144,
        \n\t\t\"materials\": 5,
        \n\t\t\"textures\": 1\n\t
    },
    \n\n\t\"urlBaseType\": \"relativeToScene\",

Anyone else having this issue?


回答1:


The syntax error is a "Unexpected token: ILLEGAL" character, probably thrown by your use of "\n\t\t" and others (escape sequences) outside strings. I don't know what you are trying to achieve with escape sequences outside strings, and I don't even know if special characters should be used in JSON.

Also, I see "\" at some of your strings. You can't use "\". You can, however, use "\", that is escape sequence for a "\". Using a single "\" inside a string will give you the "Unexpected token: ILLEGAL" error. "\" must always be followed by a character that makes a valid escape sequence.



来源:https://stackoverflow.com/questions/26437657/three-js-sceneexporter-getting-uncaught-syntax-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!