threejs实现三维3d太阳地球月球自转和公转效果代码

代码语言:html

所属分类:三维

代码描述:threejs实现三维3d太阳地球月球自转和公转效果代码

代码标签: three 太阳 月球 地球 自转 公转 三维

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

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

<head>
    <meta charset="UTF-8">
    <style>
        html,body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,a,img,p,span,i,em,b,strong,br,hr,form,input,select,label,button,table,thead,tbody,tfoot,th,td,iframe,figure,figcaption,abbr,acronym,address,caption,cite,dfn,var,del,pre,code,caption,fieldset,legend,blockquote,details,hgroup,menu,sub,sup,ins,header,nav,aside,section,aside,footer,figure,meter,progress,time,audio,source,video,command,datalist,details,canvas,embed,hgroup,keygen,mark,output,ruby{
        margin:0;
        padding:0;
        box-sizing: border-box;
    }
    html, body {
        width: 100%;
        height: 100%;
        background: #000 url(//repo.bfw.wiki/bfwrepo/images/skin/starry_sky_bg.jpg) no-repeat center center;
        overflow: hidden;
    }
    #starry-lite{
    	list-style: none;
    	position: fixed;
    	left: 0;
    	top: 0;
    	width: 110px;
    }
    #starry-lite li{
    	height: 35px;
    	line-height: 35px;
    }
    #starry-lite li p{
    	display: inline-block;
    	font-size: 14px;
    	width: 70px;
    	text-align: right;
    	color: #ffffff;
    }
    #starry-lite li img{
    	width: 30px;
    	height: 30px;
    	vertical-align: middle;
    }
    .code-frame{
    	position: fixed;
    	right: -800px;
    	top: 0;
    	width: 800px;
    	height: 100%;
    	background: rgba(0,0,0,0.5);
    	transition: all 0.3s;
    }
    .code-frame.on{
    	right: 0;
    	transition: all 0.3s;
    }
    .code-operate{
    	position: absolute;
    	width: 32px;
    	height: 64px;
    	line-height: 64px;
    	text-align: center;
    	font-weight: bold;
    	font-size: 24px;
    	color: #fff;
    	left:-32px;
    	top:50%;
    	margin-top: -32px;
    	background: rgba(0,0,0,0.5);
    	cursor: pointer;
    	border-top-left-radius: 5px;
    	border-bottom-left-radius: 5px;
    }
    .code-content{
    	width: 100%;
    	height: 100%;
    	overflow: auto;
    }
    #code-content{
    	width: 100%;
    	height: 100%;
    }
    .code-operate:hover{
    	background: rgba(0,0,0,0.8);
    }
    .ace-monokai{
    	background-color: rgba(0,0,0,0.5) !important;
    }
    .ace-monokai .ace_gutter{
    	background: rgba(0,0,0,0.7) !important;
    }
    .ace_fold-widget, .ace_info, .ace_error, .ace_text-input, .ace_warning{
    	display: none !important;
    }
    .download-frame{
    	position: absolute;
    	top: 0;
    	left: 50%;
    	margin-left: -80px;
    	width: 160px;
    	height: 50px;
    	background: rgba(0,0,0,0.5);
    	cursor: pointer;
    	color: #fff;
    	font-size: 16px;
    	line-height: 50px;
    	text-align: center;
    	border-bottom-left-radius: 5px;
    	border-bottom-right-radius: 5px;
    	text-decoration: none;
    }
    .download-frame:hover{
    	background: rgba(0,0,0,0.8);
    	color: #0268CA;
    }
    #starry-frame {
        width: 100%;
        height: 100%;
    }
    </style>
    <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/font-awesome-4.7.0/css/font-awesome.min.css">
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.126.js"></script>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/OrbitControls.126.js"></script>
</head>

<body>
    <ul id="starry-lite">
        <li>
            <p>太阳:</p><img src="//repo.bfw.wiki/bfwrepo/images/skin/sun_min_bg.png" /></li>
        <li>
            <p>地球:</p><img src="//repo.bfw.wiki/bfwrepo/images/skin/earth_min_bg.png" /></li>
        <li>
            <p>月球:</p><img src="//repo.bfw.wiki/bfwrepo/images/skin/moon_min_bg.png" /></li>
    </ul>
    <div id="starry-frame"></div>
</body>
<script>
    // 渲染器
	    var renderer = null;
	    // 相机
	    var camera = null;
	    // 场景
	    var scene = null;
	    // 中心球体(太阳)
	    var centerBall = null;
	    // 中心球体轨道组合体(行星)
	    var starLites = [];
	    // 包裹画布dom
	    var dom = document.getElementById("starry-frame");
	    // 太阳自转速度
	    var sunSpeed = 0.01;
	    // 太阳大小
	    var sunSize = 30;
	    // 太阳光照放大率
	    var sunScaleSize = 110;
	    // 太阳光颜色
	    var sunSpriteColor = '253,111,7';
	    // 太阳贴图
	    var sunImgUrl = '//repo.bfw.wiki/bfwrepo/images/skin/sun_bg.jpg';
	    // orbitcontrols对象参数
	    var orbitcontrols = null;
	    // 地月体系变量
	    var earthMesh = null;
	    // 地球变量
	    var earthLite = null;
	    // 地球公转半径
	    var earthLiteRadius = 42.2;
	    // 地球贴图
	    var imgUrl = '//repo.bfw.wiki/bfwrepo/images/skin/earth_bg.jpg';
	    // 地球大小
	    var earthLiteSize = 5.2;
	    // 地球rotation
	    var rotation = {
	    	x: -Math.PI * 0.42, 
	    	y: Math.PI * 0.02, 
	    	z: 0
	    }
	    // 地球公转速度
	    var earthRotationSpeed = 0.016;
	    // 地球自转速度
	    var earthSpeed = 0.025;
	    // 月球对象
	    var moonLite = null;
	    // 月球大小
	    var moonLiteSize = 2.5;
	    // 月球贴图
	    var imgMoonUrl = '//repo.bfw.wiki/bfwrepo/images/skin/moon_bg.jpg';
	    // 月球3d对象
	    var moonPoint = null;
	    // 月球公转速度
	    var moonSpeed = 0.02;
	    // 月球自转速度
	    var moonLiteSpeed = 0.21;
	    /**
	   .........完整代码请登录后点击上方下载按钮下载查看

网友评论0