我正在使用 Three.js 开发基于 Web 的 3D WebGL 应用程序。我正在尝试使用以下代码加载“Blender”模型 JS 文件:
var loader = new THREE.JSONLoader();
var jsonLoader = new THREE.JSONLoader();
jsonLoader.load( "../build/MySampleModel.js", addModelToScene );
// addModelToScene function is called back after model has loaded
var ambientLight = new THREE.AmbientLight(0x111111);
scene.add(ambientLight);
function addModelToScene( geometry, materials )
{
var material = new THREE.MeshFaceMaterial( materials );
meshObj = new THREE.Mesh( geometry, material );
meshObj.scale.set(10,10,10);
meshObj.add( android );
}
当我在 Chrome 浏览器中对此进行测试时,它不会加载模型并给出以下错误:
THREE.WebGLRenderer 59dev three.min.js:417
XMLHttpRequest cannot load file:///Users/xxxx/Desktop//THREE_JS_3DWEB/Dev/three.js-dev/build/MySampleModel.js. Cross origin requests are only supported for HTTP. three.min.js:211
THREE.JSONLoader: [../build/HouseModel.js] seems to be unreachable or file there is empty three.min.js:210
Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101 three.min.js:211
我的机器上没有运行任何本地服务器。在基于 Three.js 的项目中是否需要运行本地服务器来加载 Blender 模型 JS 文件?
(当我尝试运行名为“webgl_loader_json_blender.html”的 Three.js 示例文件(该文件使用加载搅拌机模型)时,在运行本地 apache 服务器的 Eclipse 中,当我运行“webgl_loader_json_blender.html”时,它能够正确加载搅拌机文件“在 Chrome 浏览器中。)
我不是专家,但你的问题似乎是浏览器的“同源策略”安全限制的问题。检查 Three.js 存储库中的此链接:https://github.com/mrdoob/ Three.js/wiki/How-to-run-things-locally https://github.com/mrdoob/three.js/wiki/How-to-run-things-locally
根据我的经验,使用 Mozilla Firefox(而不是 Chrome)加载本地模型会更容易。
所以答案是no,服务器不需要加载模型。
祝你好运!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)