【问题标题】:How to change the way shading looks on cubes in Three.js?如何更改 Three.js 中立方体上的着色方式?
【发布时间】:2012-02-27 08:23:34
【问题描述】:

我正在使用 Three.js 创建一个小游戏,除了立方体的 shome 着色问题之外,一切都进展顺利。我基本上是通过将纹理立方体放下来形成迷宫来构建游戏关卡。问题在于,当立方体彼此相邻时,每个立方体都会以这样的方式着色,看起来就像是一个单独的实体,而不是更大墙的一部分。

这里是一个例子,请注意丢失了一堵墙的错觉:

我应该使用不同的着色技术,还是在某处设置一个不错的属性来改变这种着色行为?

这是我的立方体模型:

{

    "metadata" :
    {
        "formatVersion" : 3,
        "generatedBy"   : "Blender 2.60 Exporter",
        "vertices"      : 8,
        "faces"         : 6,
        "normals"       : 8,
        "colors"        : 0,
        "uvs"           : 4,
        "materials"     : 1,
        "morphTargets"  : 0
    },

    "scale" : 1.000000,
    "materials": [{
        "DbgColor" : 15658734,
        "DbgIndex" : 0,
        "DbgName" : "WallCube",
        "colorAmbient" : [1.0, 1.0, 1.0],
        "colorDiffuse" : [1.0, 1.0, 1.0],
        "colorSpecular" : [0.15, 0.15, 0.15],
        "mapDiffuse" : "../../textures/walls/stone/stone.png",
        "mapDiffuseWrap" : ["repeat", "repeat"],
        "mapNormal" : "../../textures/walls/stone/stone_normal.png",
        "mapNormalFactor" : 1.0,
        "shading" : "Lambert",
        "specularCoef" : 25,
        "transparency" : 1.0,
        "vertexColors" : false
    }],

    "vertices": [50.000000,-50.000000,-50.000000,50.000000,-50.000000,50.000000,-50.000000,-50.000000,50.000000,-50.000000,-50.000000,-50.000000,50.000000,50.000000,-50.000000,50.000000,50.000000,50.0000050,-50.000000,50.000000,50.000000,-50.000000,50.000000,-50.000000],

    "morphTargets": [],

    "normals": [1.000000,-1.000000,-1.000000,1.000000,-1.000000,1.000000,-1.000000,-1.000000,1.000000,-1.000000,-1.000000,-1.000000,1.000000,1.000000,-1.000000,-1.000000,1.000000,-1.000000,-1.000000,1.000000,1.000000,1.000000,1.000000,1.000000],

    "colors": [],

    "uvs": [[0.000000,1.000000,1.000000,1.000000,1.000000,0.000000,0.000000,0.000000]],

    "faces": [43,0,1,2,3,0,0,1,2,3,0,1,2,3,43,4,7,6,5,0,0,1,2,3,4,5,6,7,43,0,4,5,1,0,1,2,3,0,0,4,7,1,43,1,5,6,2,0,1,2,3,0,1,7,6,2,43,2,6,7,3,0,1,2,3,0,2,6,5,3,43,4,0,3,7,0,3,0,1,2,4,0,3,5]

}

这就是我加载它的方式:

JSONLoader = new THREE.JSONLoader();

Light = new THREE.PointLight(0xFFFFFF);
Light.position = {x:0, y:75, z:350};

Meshes = [];
JSONLoader.load("../assets/models/cube.js", function(Geometry)
{
    for (var MeshIndex = 0; MeshIndex <= 5; MeshIndex++)
    {
        Meshes[MeshIndex] = new THREE.Mesh(Geometry, new THREE.MeshFaceMaterial());
        Meshes[MeshIndex].position.x = MeshIndex * 100;
        Scene.add(Meshes[MeshIndex]);
    }
});

Scene.add(Light);

任何想法如何使立方体看起来像一堵连续的墙?

【问题讨论】:

    标签: three.js shader


    【解决方案1】:
    JSONLoader.load("../assets/models/cube.js", function(Geometry)
    {
        Geometry.materials[ 0 ].shading = THREE.FlatShading;
    
        // ...
    }
    

    alterq 在three.js 网站上很好地回答了这个问题。

    https://github.com/mrdoob/three.js/issues/1258#issuecomment-3834489

    【讨论】:

      猜你喜欢
      • 2015-11-22
      • 1970-01-01
      • 2012-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-23
      • 2013-02-02
      相关资源
      最近更新 更多