<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>21three.js粒子系统</title>
<script src="lastjs/three.js"></script>
<script src="js/TrackballControls.js"></script>
<script src="js/stats.js"></script>
<script src="js/dat.gui.js"></script>
<style>
body{margin: 0;overflow: hidden;position: relative}
</style>
</head>
<body>
<div style="position: absolute">粒子系统</div>
<div id="webgl-output"></div>
<script type="text/javascript">
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45,window.innerWidth/window.innerHeight,0.1,2000);
camera.position.set(0,0,150);
camera.lookAt(scene.position);
var renderer = new THREE.WebGLRenderer();
renderer.setClearColor('#a5efa5');
renderer.setSize(window.innerWidth,window.innerHeight);
var axes = new THREE.AxisHelper(10);
scene.add(axes);
var amblight = new THREE.AmbientLight(0x666666);
scene.add(amblight);
var spotllight = new THREE.SpotLight(0xCCCCCC);
spotllight.position.set(0,50,0);
scene.add(spotllight);
document.getElementById('webgl-output').appendChild(renderer.domElement);
createSprites();
function createSprites() {
var material = new THREE.SpriteMaterial();
for (var x = -5; x < 5; x++) {
for (var y = -5; y < 5; y++) {
var sprite = new THREE.Sprite(material);
sprite.position.set(x * 10, y * 10, 0);
scene.add(sprite);
}
}
}
createParticles();
function createParticles() {
var geom = new THREE.Geometry();
var material = new THREE.PointCloudMaterial({
size:4,
vertexColors:true,color:0xffffff
});
for (var x = -5; x < 5; x++) {
for (var y = -5; y < 5; y++) {
var sprite = new THREE.Vector3(x * 10, y * 10, 10);
geom.vertices.push(sprite);
geom.colors.push(new THREE.Color(Math.random()*0xffffff));
}
}
var cloud = new THREE.PointCloud(geom,material);
scene.add(cloud);
}
renderer.render(scene,camera);
var trackballControls = new THREE.TrackballControls(camera);
var clock = new THREE.Clock();
function run() {
var delta = clock.getDelta();
trackballControls.update(delta);
requestAnimationFrame(run);
renderer.render(scene,camera);
}
run();
window.addEventListener('resize',onResize,false);
function onResize() {
camera.aspect = window.innerWidth/window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth,window.innerHeight);
}
</script>
</body>
</html>
21three.js粒子系统(一)
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...