- BabylonJS 教程
- BabylonJS - 主頁
- BabylonJS - 簡介
- BabylonJS - 環境設定
- BabylonJS - 概覽
- BabylonJS - 基本元素
- BabylonJS - 材質
- BabylonJS - 動畫
- BabylonJS - 攝像機
- BabylonJS - 光線
- BabylonJS - 引數化形狀
- BabylonJS - 蒙皮
- 向量位置和旋轉
- BabylonJS - 貼花
- BabylonJS - Curve3
- BabylonJS - 動態紋理
- BabylonJS - 視差貼圖
- BabylonJS - 鏡頭光暈
- BabylonJS - 建立螢幕截圖
- BabylonJS - 反射探針
- 標準渲染管道
- BabylonJS - ShaderMaterial
- BabylonJS - 骨骼和骨架
- BabylonJS - 物理引擎
- BabylonJS - 聲音播放和音樂播放
- BabylonJS 實用資源
- BabylonJS - 快速指南
- BabylonJS - 實用資源
- BabylonJS - 討論
BabylonJS - 映象紋理凹凸紋理
使用映象紋理,可獲得所建立蒙皮的映象反射。
映象紋理語法
mirrorMaterial.reflectionTexture = new BABYLON.MirrorTexture("mirror", 512, scene, true); //Create a mirror texture
mirrorMaterial.reflectionTexture.mirrorPlane = new BABYLON.Plane(0, -1.0, 0, -10.0);
凹凸紋理會在附加材質的蒙皮表面建立凹凸和皺紋。
凹凸紋理語法
bumpMaterial.bumpTexture = new BABYLON.Texture("images/btexture1.jpg", scene);
演示
<!doctype html>
<html>
<head>
<meta charset = "utf-8">
<title>BabylonJs - Basic Element-Creating Scene</title>
<script src = "babylon.js"></script>
<style>
canvas {width: 100%; height: 100%;}
</style>
</head>
<body>
<canvas id = "renderCanvas"></canvas>
<script type = "text/javascript">
var canvas = document.getElementById("renderCanvas");
var engine = new BABYLON.Engine(canvas, true);
var createScene = function() {
var scene = new BABYLON.Scene(engine);
scene.clearColor = new BABYLON.Color3(0, 0, 1);
var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(10, 10, 50), scene);
var light2 = new BABYLON.PointLight("Omni", new BABYLON.Vector3(10, 10, -20), scene);
var camera = new BABYLON.ArcRotateCamera("Camera", -Math.PI/2, Math.PI/4, 25, BABYLON.Vector3.Zero(), scene);
camera.attachControl(canvas, true);
var sphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 16.0, 10.0, scene);
var box1 = BABYLON.Mesh.CreateBox("box", 5.0, scene);
var sphere3 = BABYLON.Mesh.CreateSphere("Sphere3", 16.0, 10.0, scene);
var box2 = BABYLON.Mesh.CreateBox("box1", 3.0, scene);
sphere1.position.x = -20;
box1.position.x = 0;
sphere3.position.x = 20;
box2.position.z = 10;
// Mirror
var plane = BABYLON.Mesh.CreatePlane("plan", 70, scene);
plane.position.y = -10;
plane.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0);
var bumpMaterial = new BABYLON.StandardMaterial("texture1", scene);
bumpMaterial.diffuseColor = new BABYLON.Color3(0, 0, 1);//Blue
bumpMaterial.bumpTexture = new BABYLON.Texture("images/btexture1.jpg", scene);
var simpleMaterial = new BABYLON.StandardMaterial("texture2", scene);
simpleMaterial.diffuseColor = new BABYLON.Color3(1, 0, 0);//Red
var textMat = new BABYLON.StandardMaterial("texture3", scene);
textMat.diffuseTexture = new BABYLON.Texture("images/btexture1.jpg", scene);
// Multimaterial
var multimat = new BABYLON.MultiMaterial("multi", scene);
multimat.subMaterials.push(simpleMaterial);
multimat.subMaterials.push(bumpMaterial);
multimat.subMaterials.push(textMat);
//Creation of a mirror material
var mirrorMaterial = new BABYLON.StandardMaterial("texture4", scene);
mirrorMaterial.diffuseColor = new BABYLON.Color3(0.4, 0.4, 0.4);
mirrorMaterial.reflectionTexture = new BABYLON.MirrorTexture("mirror", 512, scene, true); //Create a mirror texture
mirrorMaterial.reflectionTexture.mirrorPlane = new BABYLON.Plane(0, -1.0, 0, -10.0);
mirrorMaterial.reflectionTexture.renderList = [sphere1, box1, sphere3, box2];
mirrorMaterial.reflectionTexture.level = 0.4;//Select the level (0.0 > 1.0) of the reflection
box1.subMeshes = [];
var verticesCount = box1.getTotalVertices();
box1.subMeshes.push(new BABYLON.SubMesh(0, 0, verticesCount, 0, 6, box1));
box1.subMeshes.push(new BABYLON.SubMesh(1, 1, verticesCount, 6, 6, box1));
box1.subMeshes.push(new BABYLON.SubMesh(2, 2, verticesCount, 12, 6, box1));
box1.subMeshes.push(new BABYLON.SubMesh(3, 3, verticesCount, 18, 6, box1));
box1.subMeshes.push(new BABYLON.SubMesh(4, 4, verticesCount, 24, 6, box1));
box1.subMeshes.push(new BABYLON.SubMesh(5, 5, verticesCount, 30, 6, box1));
plane.material = mirrorMaterial;
sphere1.material = bumpMaterial;
sphere3.material = simpleMaterial;
box1.material = multimat;//simpleMaterial;
return scene;
};
var scene = createScene();
engine.runRenderLoop(function() {
scene.render();
});
</script>
</body>
</html>
輸出
以下程式碼行會生成以下輸出 −
在該演示中,我們使用了名為 btexture1.jpg 的影像。這些影像儲存在本地 images/ 資料夾中,為方便參考也貼上在下方。你可以下載任何你喜歡的影像,然後在演示連結中使用。
images/btexture1.jpg
以下為用於凹凸結構的影像 −
說明
首先,我們將建立一個標準材質,並以如下方式應用凹凸紋理 −
bumpMaterial.bumpTexture = new BABYLON.Texture("images/btexture1.jpg", scene);
建立一個標準材質,並以如下方式應用映象紋理 −
mirrorMaterial.reflectionTexture = new BABYLON.MirrorTexture("mirror", 512, scene, true); //Create a mirror texture
對於相同的標準材質,建立一個映象平面,並以如下方式新增需要透過映象觀看的蒙皮 −
mirrorMaterial.reflectionTexture.mirrorPlane = new BABYLON.Plane(0, -1.0, 0, -10.0); mirrorMaterial.reflectionTexture.renderList = [sphere1, box1, sphere3, box2]; mirrorMaterial.reflectionTexture.level = 0.4;//Select the level (0.0 > 1.0) of the reflection
babylonjs_mesh.htm
廣告