Babylongjs-在Web上构建一个应用

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

        <title>Babylon Template</title>

 

        <style>

            html, body {

                overflow: hidden;

                width: 100%;

                height: 100%;

                margin: 0;

                padding: 0;

            }

 

            #renderCanvas {

                width: 100%;

                height: 100%;

                touch-action: none;

            }

        </style>

 

        <script src="https://cdn.babylonjs.com/babylon.js"></script>

        <script src="https://cdn.babylonjs.com/loaders/babylonjs.loaders.min.js"></script>

        <script src="https://code.jquery.com/pep/0.4.3/pep.js"></script>

    </head>

 

   <body>

 

    <canvas id="renderCanvas" touch-action="none"></canvas> <!-- touch-action="none" for best results from PEP -->

 

    <script>

        const canvas = document.getElementById("renderCanvas"); // Get the canvas element

        const engine = new BABYLON.Engine(canvas, true); // Generate the BABYLON 3D engine

    // 创建场景

//三要素1场景2相机3光源

        const createScene = function () {

      

            const scene = new BABYLON.Scene(engine); 

           BABYLON.MeshBuilder.CreateBox("box", {})

            const camera = new BABYLON.ArcRotateCamera("camera", -Math.PI / 2, Math.PI / 2.5, 15, new BABYLON.Vector3(0, 0, 0));

         //添加控制器

            camera.attachControl(canvas, true);

            const light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(1, 1, 0));

 

            return scene;

 

        };

 

        const scene = createScene(); //Call the createScene function

 

        // 循环渲染每帧

        engine.runRenderLoop(function () {

                scene.render();

        });

 

        // Watch for browser/canvas resize events

        window.addEventListener("resize", function () {

                engine.resize();

        });

    </script>

 

   </body>

</html>

 

这是一个最基础的WEB显示模型的代码逻辑,你需要花一点时间看看构建一个场景最基础的元素。

这是你打开WEB3D大门的第一步。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值