
- 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 - 立方體紋理
現在我們將瞭解如何使用立方體進行紋理處理。
語法
material.reflectionTexture = new BABYLON.CubeTexture("images/cubetexture/1", 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 = BABYLON.Color3.Black(); var camera = new BABYLON.ArcRotateCamera("Camera", -Math.PI/2, 0, 0, BABYLON.Vector3.Zero(), scene); var light = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(250, 250, 50), scene); camera.setPosition(new BABYLON.Vector3(0, 0, 8)); camera.upperBetaLimit = Math.PI/2; camera.lowerBetaLimit = Math.PI/2; camera.attachControl(canvas); var box = BABYLON.Mesh.CreateBox("box", 2, scene); // box material material = new BABYLON.StandardMaterial("bab5", scene); material.emissiveColor = new BABYLON.Color3(1, 1, 0); material.specularColor = new BABYLON.Color3(1, 1, 0); box.material = material; var sphere = BABYLON.Mesh.CreateSphere("sphere",32, 5, scene); // sphere material material = new BABYLON.StandardMaterial("kosh5", scene); material.diffuseColor = new BABYLON.Color3(0, 0, 0); material.reflectionTexture = new BABYLON.CubeTexture("images/cubetexture/1", scene); material.reflectionTexture.level = 1; material.specularPower = 150; material.emissiveColor = new BABYLON.Color3(0.05, 0.05, 0.05); material.alpha = 0.8; sphere.material = material; scene.registerBeforeRender(function() { box.rotation.z += 0.01; camera.alpha += 0.002; }); return scene; }; var scene = createScene(); engine.runRenderLoop(function() { scene.render(); }); </script> </body> </html>
輸出
上述程式碼行生成以下輸出 −

解釋
在上述示例中,我們使用了 cubetexture。立方體有 6 個面,因此所使用的影像具有以下名稱 −
- 1_nx.jpg
- 1_ny.jpg
- 1_nz.jpg
- 1_px.jpg
- 1_py.jpg
- 1_pz.jpg
一個立方體需要六個影像。這些影像儲存在 images/cubetexture/nameoftheimage 的本地位置。你可以下載你選擇的任何影像,但在儲存時,將其儲存為 nameoftheimage_nx、nameoftheimage_ny、nameoftheimage_nx、nameoftheimage_px、nameoftheimage_py、nameoftheimage_pz。請注意,所選影像應按順序排列,使背景看起來逼真。
images/cubetexture/1
影像如下所示 −
1_nx.jpg

1_ny.jpg

1_nz.jpg

1_px.jpg

1_py.jpg

1_pz.jpg

babylonjs_mesh.htm
廣告