three打造3d三维宇宙星际效果

代码语言:html

所属分类:三维

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

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<style>
  a {
  position: absolute;
  text-decoration: none;
  color: white;
  font-weight: 100;
  left: 50px;
  bottom: -20px;
  transition: 0.3s;
}
a:hover {
  font-weight: 300;
}
body {
  color: #000;
  font-family: Raleway;
  font-weight: 100;
  font-size: 15px;
  font-weight: bold;
  height: 100%;
  width: 100%;
  margin: 0;
  overflow: hidden;
}
#content {
  position: absolute;
}
body #container img {
  position: absolute;
  left: 50px;
  z-index: 2;
  width: 2px;
  height: 0px;
  top: 50%;
  margin-top: -100px;
}
body #container #welcome {
  opacity: 0;
  width: 900px;
  padding-left: 20px;
  color: white;
  font-size: 18pt;
  position: absolute;
  top: 50%;
  margin-top: -35px;
  left: 50px;
}
body #container #welcome #lastSentence {
  font-family: 'Raleway';
  margin: 0;
  font-weight: 400;
  font-size: 14pt;
}
body #container #welcome #firstSentence {
  font-weight: 500;
  font-size: 22pt;
  margin: 0;
  margin-bottom: 8px;
  margin-top: 2px;
}
body #container #welcome #universe {
  text-transform: uppercase;
  font-family: 'Raleway';
  font-weight: 800;
}
body #container #content {
  top: 50%;
  margin-top: -70px;
  width: 500px;
  left: 70px;
}
body #container #content h2 {
  margin: 0;
}
body #container #content span {
  font-family: Raleway;
  font-weight: 600;
}
body #container #content #contentTitle {
  font-family: Raleway;
  color: white;
  opacity: 1;
  font-weight: 200;
  letter-spacing: 1.5px;
  font-size: 26pt;
}
body #container #content #contentTitle span {
  color: #F66120;
}
body #container #content #contentTitle div {
  font-size: 12pt;
  display: inline-block;
}
body #container #content #subtitle {
  letter-spacing: 1.5px;
  margin: 0;
  font-size: 16pt;
  font-family: Raleway;
  font-weight: 200;
  color: white;
}
body #container #content #description {
  color: white;
  letter-spacing: 1.5px;
  font-family: Raleway;
  font-weight: 200;
  font-size: 16pt;
}
body #container #content #description span {
  color: #F66120;
}
body #container #content #description div {
  color: #acacac;
  font-size: 10pt;
}
body #container #content #description a {
  color: white;
  line-height: 10px;
  transition: 0.3s;
}
body #container #content #description a:hover {
  line-height: 11px;
  font-weight: 500;
}
</style>

</head>
<body translate="no">
<style>
@import url('https://fonts.googleapis.com/css?family=Raleway:100,100i,200,300,400,500,600,700,800');
</style>
<div id="container">
<img id="border" src="https://image.ibb.co/gFxj6F/border.png">
<div id="welcome">
<p id="firstSentence">Welcome to my <span id="universe">universe</span></p>
<p id="lastSentence">Click on the <span id="sun">sun</span> to get started</p>
</div>
<div id="content">
<h2 id="contentTitle"></h2>
<p id="subtitle"></p>
<p id="description"></p>
</div>
<div><a id="social" target="_blank" href="https://twitter.com/nskargovskii">follow : @nskargovskii</a></div>
</div>

<script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script>
<script src='http://repo.bfw.wiki/bfwrepo/js/TweenMax.min.js'></script>
<script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/three.js"></script>
<script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/stats-min.js"></script>
<script src='http://repo.bfw.wiki/bfwrepo/js/OrbitControls.js'></script>
<script >
      var container, stats;
var camera, controls, scene, renderer;
var info;
var cube;
var sphereTab = [];
var objects = [];
var parent2;
var sun;
var sun2;
var sun3;
var currentcolor;
var cubeNul;
var earthPivot;
var earthPivot3;
var mesh;
var planetViewed = 0;
init();
animate();
$(window).on('load', function () {
  TweenMax.to($('#welcome'), 1, {
    css: {
      opacity: 1 },

    ease: Quad.easeInOut });

  TweenMax.to($('#social'), 0.5, {
    css: {
      bottom: '20px' },
    delay: 0.5,
    ease: Quad.easeInOut });

  TweenMax.to($('#border'), 0.5, {
    css: {
      height: '200px' },

    delay: 0.5,
    ease: Quad.easeInOut });


});

function hideWelcome() {
  TweenMax.to($('#welcome'), 0.5, {
    css: {
      opacity: 0 },

    ease: Quad.easeInOut });

  TweenMax.to($('#welcome'), 0.5, {
    css: {
      display: 'none' },

    delay: 1,
    ease: Quad.easeInOut });

}

function init() {
  camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 1000);
  camera.position.z = 68;
  controls = new THREE.OrbitControls(camera);
  controls.maxDistance = 300;
  controls.minDistance = 30;
  scene = new THREE.Scene();
  var geoSphere = new THREE.SphereGeometry(Math.random() * 1, 20, 20);
  for (var i = 0; i < 500; i++) {
    // randRadius = Math.random()*30+10;
    lumiereS = new THREE.MeshPhongMaterial({
      emissive: '#fff' });

    sphereTab.push(new THREE.Mesh(new THREE.SphereGeometry(Math.random() * 1, 20, 20), lumiereS));
  }
  var posX = -3000;
  var posY = -3000;
  for (var i = 0; i < sphereTab.length; i++) {
    sphereTab[i].position.set(Math.random() * 600 - 300, Math.random() * 600 - 300, Math.random() * 600 - 300);
    scene.add(sphereTab[i]);
  }
  //////Sun////////
  var pinkMat = new THREE.MeshPhongMaterial({
    color: 0xF66120,
    emissive: 0xF66120,
    specular: 0xFFED22,
    shininess: 10,
    shading: THREE.FlatShading,
    transparent: 1,
    opacity: 1 });

  var pinkMat2 = new THREE.MeshPhongMaterial({
    color: 0xF66120,
    emissive: 0xF66120,
    specular: 0xFFED22,
    shininess: 10,
    shading: THREE.FlatShading,
    transparent: 1,
    opacity: 1 });



  var geometry = new THREE.IcosahedronGeometry(3, 1);
  var geometry2 = new THREE.IcosahedronGeometry(2.5, 1);
  var geometry4 = new THREE.IcosahedronGeometry(3, 1);
  // material
  var material = new THREE.MeshPhongMaterial({
    color: 0xffc12d,
    emissive: 0xffc12d,
    shading: THREE.FlatShading });

  var material2 = new THREE.MeshPhongMaterial({
    color: 0x26D7E7,
    emissive: 0x26D7E7,
    shading: THREE.FlatShading });

  var material4 = new THREE.MeshPhongMaterial({
    color: 0xacacac,
    emissive: 0xacacac,
    shading: THREE.FlatShading });


  sun = new THREE.Mesh(new THREE.IcosahedronGeometry(10, 1), pinkMat);
  scene.add(sun);
  objects.push(sun);
  sun2 = new THREE.Mesh(new THREE.IcosahedronGeometry(10, 1), pinkMat2);
  sun2.rotation.x = 1;
  scene.add(sun2);
  objects.push(sun2);
  sun3 = new THREE.Mesh(new THREE.IcosahedronGeometry(10, 1), pinkMat2);
  sun3.rotation.x = 1;
  scene.add(sun2);
  objects.push(sun3);

  earthPivot3 = new THREE.Object3D();
  sun.add(earthPivot3);

  var radius = 16;
  var tubeRadius = 0.03;
  var radialSegments = 8 * 10;
  var tubularSegments = 6 * 15;
  var arc = Math.PI * 3;
  var geometry3 = new THREE.TorusGeometry(radius, tubeRadius, radialSegments, tubularSegments, arc);
  var material3 = new THREE.MeshLambertMaterial({
    color: 0xffffff,
    emissive: 0xffffff,
    shading: THREE.FlatShading });

  mesh = new THREE.Mesh(geometry3, material3);
  earthPivot3.add(mesh);
  /// planet blue ///
  earthPivot = new THREE.Object3D();
  sun.add(earthPivot);
  var earth = new THREE.Mesh(geometry, material);
  earth.position.x = 15;
  earthPivot.add(earth);
  objects.push(earth);
  ///// planet gree.........完整代码请登录后点击上方下载按钮下载查看

网友评论0