Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法将纹理设置为长方体(html5/js/babylon.js)_Javascript_Html_Babylonjs - Fatal编程技术网

Javascript 无法将纹理设置为长方体(html5/js/babylon.js)

Javascript 无法将纹理设置为长方体(html5/js/babylon.js),javascript,html,babylonjs,Javascript,Html,Babylonjs,我正在试用Babylon.js。我想设置我的地板纹理,但它不起作用。我得到以下错误: “未捕获的TypeError:_this.getScene不是函数”(用于谷歌搜索) 我真的不明白,youtube教程让它看起来很简单 源代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <style>

我正在试用Babylon.js。我想设置我的地板纹理,但它不起作用。我得到以下错误:

“未捕获的TypeError:_this.getScene不是函数”(用于谷歌搜索)

我真的不明白,youtube教程让它看起来很简单

源代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
        #canvas {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <canvas id="canvas"></canvas>
    <script src="https://cdn.babylonjs.com/babylon.max.js"></script>
    <script>
        window.addEventListener('DOMContentLoaded', function () {
            var canvas = document.getElementById('canvas');
            var engine = new BABYLON.Engine(canvas, true);
            var createScene = function () {
                var scene = new BABYLON.Scene(engine);
                scene.clearColor = new BABYLON.Color3.White();

                var floor = BABYLON.MeshBuilder.CreateBox("floor", { height: 25, width: 800, depth: 900 }, scene);
                floor.position.y = -162.5;
                floor.position.x = 100;
                floor.position.z = 400;

                var camera = new BABYLON.ArcRotateCamera(
                    'camera1',
                    BABYLON.Tools.ToRadians(45),
                    BABYLON.Tools.ToRadians(45),
                    1000.0,
                    new BABYLON.Vector3(0, 50, 400),
                    scene);
                camera.attachControl(canvas, true);

                var light = new BABYLON.PointLight("pointlight", new BABYLON.Vector3(800, 700, 1000), scene);
                light.diffuse = new BABYLON.Color3(1, 1, 1);


                var floormaterial = new BABYLON.StandardMaterial("floormaterial", scene);
                floormaterial.diffuseTexture = BABYLON.Texture("floor.png", scene);
                floor.material = floormaterial;

                return scene;
            };

            var scene = createScene();
            engine.runRenderLoop(function () {
                scene.render();
            });

        });
    </script>
</body>
</html>

#帆布{
宽度:100%;
身高:100%;
}
addEventListener('DOMContentLoaded',函数(){
var canvas=document.getElementById('canvas');
var引擎=新巴比伦引擎(画布,真);
var createScene=函数(){
var场景=新巴比伦。场景(引擎);
scene.clearColor=新巴比伦.Color3.White();
var floor=BABYLON.MeshBuilder.CreateBox(“floor”,高度:25,宽度:800,深度:900},场景);
楼层位置y=-162.5;
楼层位置x=100;
楼层位置z=400;
var摄像机=新巴比伦(
“camera1”,
巴比伦.工具.托拉第安(45),
巴比伦.工具.托拉第安(45),
1000.0,
新巴比伦。矢量3(0,50,400),
场景);
照相机.附件控件(画布,真实);
var light=新巴比伦。点光源(“点光源”,新巴比伦。矢量3(8007001000),场景);
light.diffuse=新巴比伦色3(1,1,1);
var floormaterial=新巴比伦。标准材质(“floormaterial”,场景);
floormaterial.diffuseTexture=BABYLON.Texture(“floor.png”,场景);
地板材料=地板材料;
返回场景;
};
var scene=createScene();
engine.runRenderLoop(函数(){
scene.render();
});
});

如果我删除“floormaterial.diffuseTexture=BABYLON.Texture(“floor.png”,scene)”;“line一切都很完美。

你缺少了纹理前的
。线路应为:

floormatarial.diffuseTexture=新的巴比伦纹理(“floor.png”,场景);

Auch,。。我就是这样的傻瓜。非常感谢你!