three.js?????????????????????????????????

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了three.js?????????????????????????????????相关的知识,希望对你有一定的参考价值。

?????????chapter   lang   vector   its   ffffff   tcl   width   var   ??????   

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>??????</title>
    <script src="js/three.min.js"></script>
    <style>
        html, body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            /*background-color: blue;*/
        }
    </style>
</head>
<body>
<canvas></canvas>
</body>
<script src="js/chapter2.1.js"></script>
</html>

 

chapter2.1.js

1???????????????????????????????????? > ??????????????? > ??????????????? > ??????????????????????????????????????? > ??????

function threeStart() {
    initThree(); 
    initCamera();
    initScene();
    initObject();
    renderer.clear();
    renderer.render(scene, camera);
}
threeStart();

2?????????????????????

var canvas = document.querySelector("canvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

var renderer;
function initThree() {
    renderer = new THREE.WebGLRenderer({
        canvas : canvas,
        antialias : true
    });
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.setClearColor(0xffffff, 1);
}

3??????????????????

var camera;
function initCamera() {
    camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
    camera.position.x = 0;
    camera.position.y = 0;
    camera.position.z = 1000;
    camera.up.x = 0;
    camera.up.y = 1;
    camera.up.z = 0;
    camera.lookAt(0, 0, 0);
}

4??????????????????

var scene;
function initScene () {
    scene = new THREE.Scene();
}

5??????????????????????????????????????????

var line;
function initObject() {
    //??????????????????
    var p1 = new THREE.Vector3(-100, -100, 0);
    var p2 = new THREE.Vector3(100, 100, 0);

    var geometry = new THREE.Geometry();
    var material = new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors });
    geometry.vertices.push(p1);
    geometry.vertices.push(p2);

    var color1 = new THREE.Color( 0x444444 ), color2 = new THREE.Color( 0xFF0000 );
    geometry.colors.push(color1, color2);
    line = new THREE.Line(geometry, material, THREE.LineSegments);
    scene.add(line);
}

???????????????

????????????

???????????????????????????????????????vertexColors:THREE.VertexColors??????????????????????????????????????????????????????????????????

 

以上是关于three.js?????????????????????????????????的主要内容,如果未能解决你的问题,请参考以下文章

Three.js开发指南---使用three.js的材质(第四章)

three.js(16)-精灵图

three.js源码目录

three.js简介

three.js 入门详解

three.js 入门详解