babylon实现三维正方体上下移动动画效果代码

代码语言:html

所属分类:三维

代码描述:babylon实现三维正方体上下移动动画效果代码

代码标签: babylon 三维 正方体 上下 移动 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="UTF-8">



    <style>
        html, body {
          margin: 0;
          padding: 0;
          width: 100vw;
          height: 100vh;
        }
        
        canvas {
          width: 100%;
          height: 100%;
        }
    </style>


</head>

<body>
    <canvas id="renderCanvas"></canvas>

<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/babylon.5.2.0.js"></script>
    <script>
     const B = BABYLON;

class App {
	constructor() {
		this.cubes = [];
		this.canvas = document.getElementById("renderCanvas");
		this.settings = {
			numberOfCubes: 100,
			cubeSize: 5,
			camera: { alpha: 1, beta: 1, radius: 50 },
			offsetY: 5,
		};
		this.settings.light = { x: this.settings.numberOfCubes, y: 100, z: this.settings.numberOfCubes };
		this.settings.cameraTarget = { x: this.settings.numberOfCubes, y: 2.5, z: this.settings.numberOfCubes };
		this.start();
	}
	
	start() {
		this.engine = new B.Engine(this.canvas, true);
		this.scene = new B.Scene(this.engine);
		this.scene.clearColor = new B.Color3(0.1, 0.1, 0.1);
		this.target = new B.MeshBuilder.CreateSphere("target", this.scene);
		this.target.material = new B.StandardMaterial("target-material", this.scene);
		this.target.material.emissiveColor = new B.Color3(1, 0, 0);
		this.target.position = new B.Vector3(this.settings.cameraTarget.x, this.settings.cameraTarget.y, this.settings.cameraTarget.z);
		this.target.material.alpha = 0;
		this.camera = new B.ArcRotateCamera("Camera", this.settings.camera.alpha, this.settings.camera.beta, this.settings.camera.radius, this.target, this.scene);
		this.camera.attachControl(this.canvas, true);
		this.camera.useAutoRotationBehavior = true;
		this.camera.autoRotationBehavior.idleRotationSpeed = 0.1;
		this.light = new.........完整代码请登录后点击上方下载按钮下载查看

网友评论0