思路:加载纹理贴图,批量创建精灵模型,然后随机生成。下落到指定位置就重新生成
<!DOCTYPE html
>
<html lang
="en">
<head
>
<meta charset
="UTF-8">
<title
>笑脸雨
</title
>
<style
>
body
{
margin
: 0;
overflow
: hidden
;
}
</style
>
<!--引入three
.js三维引擎
-->
<script src
="../../js/three.js"></script
>
<script src
="../../js/OrbitControls.js"></script
>
<!-- <script src
="./three.js"></script
> -->
</head
>
<body
>
<script type
="text/javascript">
var scene
,camera
,renderer
,
light
,group
;
init();
function init(){
initScene();
initCamera();
initRenender();
initLight();
initOthers();
setWindown();
initaxisHelper();
yu();
}
function initScene(){
scene
= new THREE.Scene();
}
function initCamera(){
camera
= new THREE.PerspectiveCamera(60, window
.innerWidth
/ window
.innerHeight
, 1, 1000);
camera
.position
.set(292, 109, 268);
camera
.lookAt(scene
.position
);
}
function initRenender(){
renderer
= new THREE.WebGLRenderer();
renderer
.setSize(window
.innerWidth
, window
.innerHeight
);
}
function initOthers(){
document
.body
.appendChild(renderer
.domElement
);
}
function yu() {
var textureTree
= new THREE.TextureLoader().load("../../img/笑笑.jpg");
console
.log(textureTree
)
group
= new THREE.Group();
for (let i
= 0; i
< 400; i
++) {
var spriteMaterial
= new THREE.SpriteMaterial({
map
:textureTree
,
});
var sprite
= new THREE.Sprite(spriteMaterial
);
sprite
.scale
.set(8, 10, 1);
var k1
= Math
.random() - 0.5;
var k2
= Math
.random() - 0.5;
sprite
.position
.set(1000 * k1
, 300 * Math
.random(), 1000 * k2
)
group
.add(sprite
);
}
scene
.add(group
);
}
function setWindown(){
window
.addEventListener('resize', function(){
var width
= window
.innerWidth
;
var height
= window
.innerHeight
;
renderer
.setSize(width
,height
);
camera
.aspect
= width
/height
;
camera
.updateProjectionMatrix();
});
}
function initaxisHelper() {
var axisHelper
= new THREE.AxisHelper(250);
scene
.add(axisHelper
);
}
function initLight(){
light
= new THREE.Light(0xFFFFFF,1.0);
scene
.add(light
);
}
var update=function(){
}
function render() {
group
.children
.forEach(sprite
=> {
sprite
.position
.y
-= 1;
if (sprite
.position
.y
< 0) {
sprite
.position
.y
= 200;
}
});
renderer
.render(scene
, camera
);
}
var loop=function() {
requestAnimationFrame(loop
);
update();
render();
}
loop();
</script
>
</body
>
</html
>
转载请注明原文地址:https://tech.qufami.com/read-11117.html