提交 b69e19e8 编写于 作者: M Mr.doob

Promoted BufferGeometry from src/extras/core to scr/core. Added basic example.

上级 6bdaf52a
此差异已折叠。
此差异已折叠。
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - buffergeometry</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
color: #808080;
font-family:Monospace;
font-size:13px;
text-align:center;
background-color: #fff;
margin: 0px;
overflow: hidden;
}
#info {
position: absolute;
top: 0px; width: 100%;
padding: 5px;
}
a {
color: #0080ff;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> webgl - buffergeometry</div>
<script src="../build/three.js"></script>
<script src="js/Detector.js"></script>
<script src="js/Stats.js"></script>
<script>
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
var container, stats;
var camera, scene, renderer;
var mesh;
init();
animate();
function init() {
container = document.getElementById( 'container' );
camera = new THREE.PerspectiveCamera( 20, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 1800;
scene = new THREE.Scene();
var triangles = 500;
var geometry = new THREE.BufferGeometry();
geometry.attributes = {
index: {
itemSize: 1,
array: new Int16Array( triangles * 3 ),
numItems: triangles * 3
},
position: {
itemSize: 3,
array: new Float32Array( triangles * 3 * 3 ),
numItems: triangles * 3 * 3
}
}
var indices = geometry.attributes.index.array;
for ( var i = 0; i < indices.length; i ++ ) {
indices[ i ] = i;
}
var positions = geometry.attributes.position.array;
for ( var i = 0; i < positions.length; i += 9 ) {
var x = Math.random() * 400 - 200;
var y = Math.random() * 400 - 200;
var z = Math.random() * 400 - 200;
positions[ i ] = x + Math.random() * 40 - 20;
positions[ i + 1 ] = y + Math.random() * 40 - 20;
positions[ i + 2 ] = z + Math.random() * 40 - 20;
positions[ i + 3 ] = x + Math.random() * 40 - 20;
positions[ i + 4 ] = y + Math.random() * 40 - 20;
positions[ i + 5 ] = z + Math.random() * 40 - 20;
positions[ i + 6 ] = x + Math.random() * 40 - 20;
positions[ i + 7 ] = y + Math.random() * 40 - 20;
positions[ i + 8 ] = z + Math.random() * 40 - 20;
}
geometry.offsets = [{
start: 0,
count: triangles * 3,
index: 0
}]
geometry.computeBoundingSphere()
geometry.computeVertexNormals()
mesh = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: 0x000000, side: THREE.DoubleSide } ) );
scene.add( mesh );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
container.appendChild( stats.domElement );
//
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize() {
windowHalfX = window.innerWidth / 2;
windowHalfY = window.innerHeight / 2;
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
//
function animate() {
requestAnimationFrame( animate );
render();
stats.update();
}
function render() {
mesh.rotation.x += 0.01;
mesh.rotation.y += 0.02;
renderer.render( scene, camera );
}
</script>
</body>
</html>
......@@ -32,7 +32,7 @@
<body>
<div id="container"></div>
<div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - vertex colors - webgl</div>
<div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> webgl - vertex colors</div>
<script src="../build/three.min.js"></script>
......
......@@ -234,15 +234,15 @@ THREE.BufferGeometry.prototype = {
ab.sub( pA, pB );
cb.crossSelf( ab );
normals[ vA * 3 ] += cb.x;
normals[ vA * 3 ] += cb.x;
normals[ vA * 3 + 1 ] += cb.y;
normals[ vA * 3 + 2 ] += cb.z;
normals[ vB * 3 ] += cb.x;
normals[ vB * 3 ] += cb.x;
normals[ vB * 3 + 1 ] += cb.y;
normals[ vB * 3 + 2 ] += cb.z;
normals[ vC * 3 ] += cb.x;
normals[ vC * 3 ] += cb.x;
normals[ vC * 3 + 1 ] += cb.y;
normals[ vC * 3 + 2 ] += cb.z;
......@@ -260,7 +260,7 @@ THREE.BufferGeometry.prototype = {
var n = 1.0 / Math.sqrt( x * x + y * y + z * z );
normals[ i ] *= n;
normals[ i ] *= n;
normals[ i + 1 ] *= n;
normals[ i + 2 ] *= n;
......@@ -372,13 +372,17 @@ THREE.BufferGeometry.prototype = {
r = 1.0 / ( s1 * t2 - s2 * t1 );
sdir.set( ( t2 * x1 - t1 * x2 ) * r,
( t2 * y1 - t1 * y2 ) * r,
( t2 * z1 - t1 * z2 ) * r );
tdir.set( ( s1 * x2 - s2 * x1 ) * r,
( s1 * y2 - s2 * y1 ) * r,
( s1 * z2 - s2 * z1 ) * r );
sdir.set(
( t2 * x1 - t1 * x2 ) * r,
( t2 * y1 - t1 * y2 ) * r,
( t2 * z1 - t1 * z2 ) * r
);
tdir.set(
( s1 * x2 - s2 * x1 ) * r,
( s1 * y2 - s2 * y1 ) * r,
( s1 * z2 - s2 * z1 ) * r
);
tan1[ a ].addSelf( sdir );
tan1[ b ].addSelf( sdir );
......
......@@ -21,6 +21,7 @@
"../src/core/Face4.js",
"../src/core/UV.js",
"../src/core/Geometry.js",
"../src/core/BufferGeometry.js",
"../src/core/Spline.js",
"../src/cameras/Camera.js",
"../src/cameras/OrthographicCamera.js",
......@@ -84,7 +85,6 @@
"../src/extras/SceneUtils.js",
"../src/extras/ShaderUtils.js",
"../src/extras/FontUtils.js",
"../src/extras/core/BufferGeometry.js",
"../src/extras/core/Curve.js",
"../src/extras/core/CurvePath.js",
"../src/extras/core/Gyroscope.js",
......@@ -216,6 +216,7 @@
"../src/core/Face4.js",
"../src/core/UV.js",
"../src/core/Geometry.js",
"../src/core/BufferGeometry.js",
"../src/core/Spline.js",
"../src/cameras/Camera.js",
"../src/cameras/OrthographicCamera.js",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册