html5 3d变形,HTML5/WebGL粒子组成的3D对象变形动画

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

class Scene {

constructor() {

this.scene,

this.camera,

this.renderer,

this.element,

this.container,

this.effect,

this.controls,

this.clock;

this.init();

}

init() {

this.scene = new THREE.Scene();

this.camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 2000);

this.camera.position.set(500, 300, 500);

this.camera.lookAt(0, 30, 0);

this.scene.add(this.camera);

this.renderer = new THREE.WebGLRenderer({

antialias: true,

alpha: true

});

// this.renderer.setClearColor( 0x202020 , 1 );

this.renderer.shadowMapEnabled = true;

this.renderer.shadowMapType = THREE.PCFSoftShadowMap;

this.element = this.renderer.domElement;

this.container = document.getElementById('webglviewer');

this.container.width = this.element.width = window.innerWidth;

this.container.height = this.element.height = window.innerHeight;

this.container.appendChild(this.element);

this.controls = new THREE.OrbitControls(this.camera, this.element);

// this.controls.target.set(

// this.camera.position.x + 0.15,

// this.camera.position.y,

// this.camera.position.z

// );

// this.controls.noPan = true;

// this.controls.noZoom = true;

// this.floor();

this.lights();

this.initShapes();

this.animate();

}

animate() {

this.raf = requestAnimationFrame(() => this.animate());

this.render();

}

lights() {

var Hlight = new THREE.AmbientLight(0x000000);

this.scene.add(Hlight);

}

initShapes() {

var model = new THREE.IcosahedronGeometry(100, 3);

var shape = new THREE.IcosahedronGeometry(1, 1);

var material = new THREE.MeshLambertMaterial({

color: 0xFFFFFF,

shading: THREE.FlatShading

});

for (var i = model.vertices.length - 1; i >= 0; i--) {

let mesh = new THREE.Mesh(shape, material);

mesh.position.x = 0;

mesh.position.y = 0;

mesh.position.z = 0;

var tl = new TimelineMax({

repeat: -1,

delay: ((model.vertices[i].x / 50) + model.vertices[i].y / 50) / 2

});

tl.to(mesh.position, 3, {

x: model.vertices[i].x,

y: model.vertices[i].y,

z: model.vertices[i].z,

ease: Power2.EaseInOut

});

tl.to(mesh.position, 2, {

x: model.vertices[i].x / 2,

y: model.vertices[i].y / 2,

z: model.vertices[i].z / 2,

ease: Power2.EaseInOut

});

this.scene.add(mesh);

}

}

resize() {

var width = this.container.offsetWidth;

var height = this.container.offsetHeight;

this.camera.aspect = width / height;

this.camera.updateProjectionMatrix();

this.renderer.setSize(width, height);

// this.effect.setSize(width, height);

}

render() {

this.resize();

// this.controls.update();

this.camera.updateProjectionMatrix();

this.renderer.render(this.scene, this.camera);

}

}

new Scene();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值