three打造一个土星旋转动画效果代码

代码语言:html

所属分类:三维

代码描述:three打造一个土星旋转动画效果代码

代码标签: 土星 旋转 动画 效果

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

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

<head>

  <meta charset="UTF-8">
  

  
  
  
  
<style>
body {
  margin: 0;
}
#world {
  position: absolute;
  overflow: hidden;
  width: 100%;
  height: 100%;
}
</style>




</head>

<body >
  <div id='world'></div>


<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.84.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/OrbitControls.min.js"></script>
      <script>
'use strict';

let scene,
camera,
renderer,
controls;

let particles,
saturn;

let width = window.innerWidth,
height = window.innerHeight;

const colors = [0x37BE95, 0xF3F3F3, 0x6549C0];

init();
animate();

function init() {
  scene = new THREE.Scene();
  camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000);
  camera.lookAt(scene.position);
  camera.position.z = 500;

  renderer = new THREE.WebGLRenderer();
  renderer.setPixelRatio(window.devicePixelRatio);
  renderer.setSize(width, height);
  renderer.setClearColor(0x0E2255);
  renderer.shadowMap.enabled = true;

  // controls = new THREE.OrbitControls(camera, renderer.domElement);

  const ambientLight = new THREE.AmbientLight();
  scene.add(ambientLight);

  const light = new THREE.DirectionalLight();
  light.position.set(200, 100, 200);
  light.castShadow = true;
  light.shadow.camera.left = -100;
  light.shadow.camera.right = 100;
  light.shadow.camera.top = 100;
  light.shadow.camera.bottom = -100;
  scene.add(light);

  drawParticles();
  drawSaturn();

  document.getElementById('world').appendChild(renderer.domElement);

  window.addEventListener('resize', onResize);
}

function onResize() {
  width = window.inne.........完整代码请登录后点击上方下载按钮下载查看

网友评论0