0

所以我在 Three.js 上了一堂课,却发现我没有受过如何加载模型的教育。我在 Turbosquid.com 上找到了一个模型<http://storage2.turbosquid.com/Download/index.php?ID=717563_8377529>,并使用 convert_obj_three.py 成功地将其转换为 JSON。

我已经搜索了好的代码,并在 stackoverflow 上找到了一些不错的示例,但是由于某种原因,当我在 chrome 中运行它时,我没有得到任何模型。

<html>
<head></head>

<body>

    <script src="http://threejs.org/build/three.js"></script>
    <script>

        var scene = new THREE.Scene();
        var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);

        var geometry;

        var renderer = new THREE.WebGLRenderer();
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(renderer.domElement);

        var material = new THREE.MeshBasicMaterial({color: 0x00ff00});

        loader = new THREE.JSONLoader();

        loader.load( "LeePerrySmith.js", function( geometry ) {

            mesh = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial() );
            mesh.scale.set( 10, 10, 10 );
            mesh.position.y = 0;
            mesh.position.x = 0;
            mesh.scale.set( 100, 100, 100 );
            scene.add( mesh );
            mesh.side = THREE.DoubleSide;
            alert("hit");

            } );


        camera.position.z = 5;

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

        render();

    </script>
</body>

我将 HTML 文件和 e100.js 模型文件存储在同一目录中。是否有一些我不知道的路径?

4

1 回答 1

1

好吧,我已经用我导出为 js 文件的简单多维数据集在这里测试了你的代码,它工作正常。最初我会怀疑三件事:

1)也许网格非常小,你看不到它,试试看mesh.scale.set( 100, 100, 100 );是否会改变任何东西。减少相机的 z 位置以“移入”一点。

2)路径看起来不错,如果你想更加确定,你可以使用像“./e100.js”这样的相对路径,但这真的没有必要。

3)也许网格有反转的法线,或者其他一些缺陷。只是为了测试,您可以尝试设置网格以在两侧渲染纹理,看看是否是这样的问题:

mesh.side = THREE.DoubleSide;

或者您可以尝试更基本的材料,例如MeshBasicMaterial代替或您的普通版本,看看是否有帮助。

在模型加载时保持控制台打开,查找任何错误。如果这些都不起作用,我会怀疑这个模型,但在这一点上这是过激的。

狩猎愉快,

编辑:cube.js

{
"metadata" :
{
"formatVersion" : 3.1,
"generatedBy" : "Blender 2.66 Exporter",
"vertices" : 8,
"faces" : 6,
"normals" : 8,
"colors" : 0,
"uvs" : [24],
"materials" : 1,
"morphTargets" : 0,
"bones" : 0
},
"scale" : 1.000000,
"materials" : [ {
        "DbgColor" : 15658734,
        "DbgIndex" : 0,
        "DbgName" : "Material",
        "blending" : "NormalBlending",
        "colorAmbient" : [0.6400000190734865, 0.6400000190734865, 0.6400000190734865],
        "colorDiffuse" : [0.6400000190734865, 0.6400000190734865, 0.6400000190734865],
        "colorSpecular" : [0.5, 0.5, 0.5],
        "depthTest" : true,
        "depthWrite" : true,
        "mapDiffuse" : "cube.png",
        "mapDiffuseWrap" : ["repeat", "repeat"],
        "shading" : "Phong",
        "specularCoef" : 50,
        "transparency" : 1.0,
        "transparent" : false,
        "vertexColors" : false
    }],
"vertices" : [1,-1,-1,1,-1,1,-1,-1,1,-1,-1,-1,1,1,-1,0.999999,1,1,-1,1,1,-1,1,-1],
"morphTargets" : [],
"normals" : [0.577349,-0.577349,-0.577349,0.577349,-0.577349,0.577349,-0.577349,-0.577349,0.577349,-0.577349,-0.577349,-0.577349,0.577349,0.577349,-0.577349,-0.577349,0.577349,-0.577349,-0.577349,0.577349,0.577349,0.577349,0.577349,0.577349],
"colors" : [],
"uvs" : [[0.33408,0.333114,0.334191,0.659296,0.009852,0.659305,0.009721,0.333137,0.991035,0.334072,0.663423,0.334025,0.663036,0.005624,0.991002,0.005943,0.991246,0.333487,0.991261,0.6585,0.663173,0.658447,0.662825,0.334005,0.662568,0.33421,0.662689,0.65851,0.335127,0.658476,0.335112,0.333952,0.335825,0.007042,0.335835,0.333228,0.008133,0.333306,0.008138,0.006861,0.335761,0.333299,0.335071,0.005883,0.663081,0.006277,0.663095,0.333865]],
"faces" : [43,0,1,2,3,0,0,1,2,3,0,1,2,3,43,4,7,6,5,0,4,5,6,7,4,5,6,7,43,0,4,5,1,0,8,9,10,11,0,4,7,1,43,1,5,6,2,0,12,13,14,15,1,7,6,2,43,2,6,7,3,0,16,17,18,19,2,6,5,3,43,4,0,3,7,0,20,21,22,23,4,0,3,5],
"bones" : [],
"skinIndices" : [],
"skinWeights" : [],
"animation" : {}
}
于 2013-08-26T22:08:31.820 回答