Three.js:无论如何,jsonLoader都不会加载纹理

时间:2016-02-21 00:44:12

标签: javascript html json three.js blender

帮助,我有多次脑痉挛试图解决这个问题。我使用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>

Json文件(titled.json):

"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"
}],

---编辑---响应gaitat ---

我知道。

之前我使用旧版本的blender插件&#34; io_mesh_three&#34;我会选择与我现在选择的设置相同的设置,并且会在json文件中引用我的纹理。但是,我最近发现,根据mrdoob在这里发现的旧的搅拌器插件:(https://github.com/mrdoob/three.js/tree/master/utils/exporters/blender)已被完全替换。所以我安装了新的插件,并且使用新的导出器选项ui我无法告诉我是否使用相同的设置,但是参考将不再显示,所以我认为它只是没有&# 39; t需要参考。我认为我无法理解发生了什么,因为对于更新版本的three.js,网上没有很多支持。我发现的大多数内容都支持旧版本,所以我只是想钓鱼尝试找到一个解决方案,让我的代码加载我的json文件并应用纹理。

0 个答案:

没有答案