Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Three.js:jsonLoader无论发生什么情况都不会加载纹理_Javascript_Html_Json_Three.js_Blender - Fatal编程技术网

Javascript Three.js:jsonLoader无论发生什么情况都不会加载纹理

Javascript Three.js:jsonLoader无论发生什么情况都不会加载纹理,javascript,html,json,three.js,blender,Javascript,Html,Json,Three.js,Blender,救命啊,我有多处脑痉挛想弄清楚。我正在使用r74最新版本的threejs,我在blender中创建了一个模型,并使用最新的插件将其导出。当我运行我的程序时,它可以加载3d文件,但是它也应该加载纹理并应用它,对吗?事实并非如此,根据我在网上看到的一切和我读到的每一篇文章,我都做得对。那真见鬼!three.js现在坏了吗 不管怎样,抛开咆哮不谈,下面是我的javascript代码: <!doctype html> <html lang="en"> <head> &

救命啊,我有多处脑痉挛想弄清楚。我正在使用r74最新版本的threejs,我在blender中创建了一个模型,并使用最新的插件将其导出。当我运行我的程序时,它可以加载3d文件,但是它也应该加载纹理并应用它,对吗?事实并非如此,根据我在网上看到的一切和我读到的每一篇文章,我都做得对。那真见鬼!three.js现在坏了吗

不管怎样,抛开咆哮不谈,下面是我的javascript代码:

<!doctype html>
<html lang="en">
<head>
<title>Imported Model (Three.js)</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link rel=stylesheet href="css/base.css"/>
</head>
<body>

  <script src="js/three.js"></script>
  <script src="js/Detector.js"></script>
  <script src="js/Stats.js"></script>
  <script src="js/OrbitControls.js"></script>
  <script src="js/THREEx.KeyboardState.js"></script>
  <script src="js/THREEx.FullScreen.js"></script>
  <script src="js/THREEx.WindowResize.js"></script>

  <!-- jQuery code to display an information button and box when clicked. -->
  <script src="js/jquery-1.9.1.js"></script>
  <script src="js/jquery-ui.js"></script>
  <link rel=stylesheet href="css/jquery-ui.css" />
  <link rel=stylesheet href="css/info.css"/>

    <script src="js/info.js"></script>
      <div id="infoButton"></div>
      <div id="infoBox" title="Demo Information">
   This three.js demo is part of a collection at
   <a href="http://stemkoski.github.io/Three.js/">http://stemkoski.github.io/Three.js/</a>
</div>

<div id="ThreeJS" style="position: absolute; left:0px; top:0px"></div>
<script>

// MAIN

// standard global variables
var container, scene, camera, renderer, controls, stats;
var keyboard = new THREEx.KeyboardState();
var clock = new THREE.Clock();

// custom global variables
var android;

init();
animate();

// FUNCTIONS        
function init() 
{
// SCENE
scene = new THREE.Scene();
// CAMERA
var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
var VIEW_ANGLE = 45, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 20000;
camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR);
scene.add(camera);
camera.position.set(0,150,400);
camera.lookAt(scene.position);  
// RENDERER
renderer = new THREE.WebGLRenderer( {antialias:true} );
renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
container = document.getElementById( 'ThreeJS' );
container.appendChild( renderer.domElement );
// EVENTS
THREEx.WindowResize(renderer, camera);
THREEx.FullScreen.bindKey({ charCode : 'm'.charCodeAt(0) });
// CONTROLS
controls = new THREE.OrbitControls( camera, renderer.domElement );
// STATS
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.bottom = '0px';
stats.domElement.style.zIndex = 100;
container.appendChild( stats.domElement );
// LIGHT
var light = new THREE.PointLight(0xffffff);
light.position.set(-100,200,100);
scene.add(light);
// SKYBOX/FOG
var skyBoxGeometry = new THREE.CubeGeometry( 10000, 10000, 10000 );
var skyBoxMaterial = new THREE.MeshBasicMaterial( { color: 0x9999ff, side: THREE.BackSide } );
var skyBox = new THREE.Mesh( skyBoxGeometry, skyBoxMaterial );
// scene.add(skyBox);
scene.fog = new THREE.FogExp2( 0x9999ff, 0.00025 );


//JSON LOADER HERE !!!!!!!

// Note: if imported model appears too dark,
//   add an ambient light in this file
//   and increase values in model's exported .js file
//    to e.g. "colorAmbient" : [0.75, 0.75, 0.75]
var jsonLoader = new THREE.JSONLoader();
jsonLoader.load("map/titled.json", addModelToScene );
jsonLoader.setTexturePath("http://localhost:8080/map/");
// 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 );
mesh = new THREE.Mesh( geometry, material );
mesh.scale.set(10,10,10);
scene.add( mesh );
}

function animate() 
{
    requestAnimationFrame( animate );
    render();       
    update();
}

function update()
{
if ( keyboard.pressed("z") ) 
{ 
    // do something
}

controls.update();
stats.update();
}

function render() 
{
    renderer.render( scene, camera );
}

</script>

</body>
</html>
---编辑---回应gaitat---

我知道


早些时候,我使用的是旧版本的blender插件“io_mesh_three”,我会选择与现在选择的设置相同的设置,json文件中将引用我的纹理。然而,我最近发现旧的搅拌机插件,根据mrdoob在这里发现:(),已经被完全替换了。因此,我安装了新的插件,使用新的exporter options ui,我无法判断是否使用了相同的设置,但引用将不再显示,因此我认为它不需要引用。我想我很难理解到底发生了什么,因为没有太多关于three.js最新版本的在线支持。我发现的大部分内容都是对旧版本的支持,所以我只是想尝试找到一个解决方案,让我的代码加载我的json文件并应用纹理。

你的json材质没有对纹理的引用我如何使它有对纹理的引用,我终于得到了要加载的纹理。我终于找到了从blender导出的正确设置。看来这一直是我的问题。下次我会考虑确定我的导出设置。谢谢你的帮助,gaitat.你的json材料没有对纹理的引用我如何使它有对纹理的引用Kay,在进一步处理这个问题后,我终于得到了我的纹理来加载。我终于找到了从blender导出的正确设置。看来这一直是我的问题。下次我会考虑确定我的导出设置。谢谢你的帮助。
"materials":[{
    "DbgIndex":81,
    "DbgColor":15658734,
    "depthTest":true,
    "shading":"phong",
    "wireframe":false,
    "depthWrite":true,
    "transparent":false,
    "DbgName":"Material.002",
    "colorSpecular":[0.5,0.5,0.5],
    "visible":true,
    "colorEmissive":[0,0,0],
    "opacity":1,
    "colorDiffuse":[0.64,0.64,0.64],
    "specularCoef":50,
    "blending":"NormalBlending"
},{
    "DbgIndex":117,
    "DbgColor":15658734,
    "depthTest":true,
    "shading":"phong",
    "wireframe":false,
    "depthWrite":true,
    "transparent":false,
    "DbgName":"Material",
    "colorSpecular":[0.5,0.5,0.5],
    "visible":true,
    "colorEmissive":[0,0,0],
    "opacity":1,
    "colorDiffuse":[0.64,0.64,0.64],
    "specularCoef":50,
    "blending":"NormalBlending"
}],