Bunny Particles
How do I make an bunny particles?
What is a bunny particles? How do you make a bunny particles? This script and codes were developed by Kenji Saito on 14 June 2022, Tuesday.
Bunny Particles - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Bunny Particles</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
</head>
<body> <script src='https://cdnjs.cloudflare.com/ajax/libs/three.js/r80/three.min.js'></script>
<script src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/13842/OBJLoader.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.0/TweenMax.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Bunny Particles - Script Codes JS Codes
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var camera, scene, renderer, mouse, stats, geometry, shaderMaterial, mesh, clock;
var isLoop;
var objLoader;
var targetArr = [];
var particles = [];
var positionAttribute;
var MAX_COUNT = 60000;
var time = 0;
var utils = { range: function range(min, max) { return min + (max - min) * Math.random(); }
};
var Particle = function () { function Particle(x, y, z, index, targetIndex) { _classCallCheck(this, Particle); this.x = x; this.y = y; this.z = z; this.prevX = this.x; this.prevY = this.y; this.prevZ = this.z; this.index = index; this.targetIndex = targetIndex; } Particle.prototype.updateTarget = function updateTarget(isDelay) { this.targetIndex = (this.targetIndex + 1) % targetArr.length; var targetPos = targetArr[this.targetIndex]; TweenMax.to(this, 2, { x: targetPos.x, y: targetPos.y, z: targetPos.z, delay: isDelay ? utils.range(0, 2) : 0.0, onUpdate: this.onUpdateParticle, onUpdateScope: this, onComplete: this.updateTarget, onCompleteScope: this }); }; Particle.prototype.onUpdateParticle = function onUpdateParticle() { positionAttribute.setXYZ(this.index * 2, this.prevX, this.prevY, this.prevZ); positionAttribute.setXYZ(this.index * 2 + 1, this.x, this.y, this.z); this.prevX = this.x; this.prevY = this.y; this.prevZ = this.z; }; return Particle;
}();
function init(group) { camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 10000); // camera.position.z = 1.2; // camera.position.y = 0.5; camera.position.z = 20; camera.position.y = 20; camera.lookAt(new THREE.Vector3()); scene = new THREE.Scene(); /** mesh = group.children[0]; console.log(mesh.geometry); mesh.material = new THREE.MeshBasicMaterial({wireframe: true, color : 0xffff00}) mesh.scale.set(10, 10, 10); mesh.position.y = -1; scene.add(group); */ // line material var material = new THREE.LineBasicMaterial({ color: new THREE.Color("rgb(" + parseInt(0.2 * 255) + ", " + parseInt(0.3 * 255) + "," + parseInt(0.4 * 255) + ")"), blending: THREE.AdditiveBlending, depthTest: false, transparent: true, opacity: 0.6 }); var indices = []; var positions = new Float32Array(MAX_COUNT * 3); var geometry = group.children[0].geometry; var positionArr = geometry.attributes.position.array; var positionCount = positionArr.length / 3; var scale = 150; var size = 0.1; for (var ii = 0; ii < positionCount; ii++) { var pos = new THREE.Vector3(positionArr[3 * ii] * scale, positionArr[3 * ii + 1] * scale, positionArr[3 * ii + 2] * scale); targetArr.push(pos); } for (var ii = 0; ii < MAX_COUNT / 2; ii++) { var index = parseInt(targetArr.length * Math.random()); var pos = targetArr[index]; particles[ii] = new Particle(pos.x, pos.y, pos.z, ii, index); if (Math.random() < 0.9) { particles[ii].updateTarget(true); } positions[6 * ii] = pos.x; positions[6 * ii + 1] = pos.y; positions[6 * ii + 2] = pos.z; positions[6 * ii + 3] = pos.x + utils.range(-size, size); positions[6 * ii + 4] = pos.y + utils.range(-size, size); positions[6 * ii + 5] = pos.z + utils.range(-size, size); } for (var ii = 0; ii < MAX_COUNT / 2; ii++) { indices.push(2 * ii); indices.push(2 * ii + 1); } var geometry = new THREE.BufferGeometry(); positionAttribute = new THREE.BufferAttribute(positions, 3); geometry.addAttribute('position', positionAttribute); geometry.setIndex(new THREE.BufferAttribute(new Uint16Array(indices), 1)); var line = new THREE.LineSegments(geometry, material); line.position.set(5, -15, 0); scene.add(line); renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setSize(window.innerWidth, window.innerHeight); renderer.setClearColor(0x000000); clock = new THREE.Clock(); document.body.appendChild(renderer.domElement); document.addEventListener('mousemove', onDocumentMouseMove, false);
}
function loop() { var delta = clock.getDelta(); time += delta; positionAttribute.needsUpdate = true; camera.position.z = 20 * Math.cos(time / 3); camera.position.x = 20 * Math.sin(time / 3); camera.lookAt(new THREE.Vector3()); // mesh.rotation.x += 0.01; // mesh.rotation.y += 0.02; renderer.render(scene, camera);
}
objLoader = new THREE.OBJLoader();
objLoader.load("https://s3-us-west-2.amazonaws.com/s.cdpn.io/13842/bunny.obj", onLoadObj);
function onLoadObj(geo) { init(geo); isLoop = true; TweenMax.ticker.addEventListener("tick", loop);
}
function onDocumentMouseMove(event) { event.preventDefault(); if (!mouse) mouse = new THREE.Vector2(); mouse.x = event.clientX / window.innerWidth * 2 - 1; mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
}
window.addEventListener("resize", function (ev) { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight);
});
window.addEventListener('keydown', function (ev) { switch (ev.which) { case 27: isLoop = !isLoop; if (isLoop) { clock.stop(); TweenMax.ticker.addEventListener("tick", loop); } else { clock.start(); TweenMax.ticker.removeEventListener("tick", loop); } break; }
});
Developer | Kenji Saito |
Username | kenjiSpecial |
Uploaded | June 14, 2022 |
Rating | 4.5 |
Size | 5,418 Kb |
Views | 50,600 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Gl particle sns icons. | 7,184 Kb |
Balls meet boxes. | 5,294 Kb |
Three.js loader cube | 2,733 Kb |
Gl loader. | 2,932 Kb |
Lines | 4,486 Kb |
A Pen by Kenji Saito | 3,433 Kb |
Particle Alphabet Roulette | 8,785 Kb |
Box, box, box. | 9,595 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Sample Profile Screen | OurDailyBread | 5,375 Kb |
Experiments with Vertical Centering | KatieK2 | 3,924 Kb |
Filtering with shuffle.js | Deyand | 2,712 Kb |
Background-blend-mode Test | 0x04 | 4,744 Kb |
A Pen by Shidhin | Shidhincr | 5,015 Kb |
Vanilla JS - A toggleClass function | Woodwork | 2,532 Kb |
Fireworks Show | Arianalynn | 3,048 Kb |
Sony Xperia Z3 Flat MockUp | Dapinitial | 4,379 Kb |
Bezier Animation with straight paths | Rhernando | 2,087 Kb |
Vertically rotating text with CSS | Nopr | 2,141 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!