Cannon.js test
How do I make an cannon.js test?
What is a cannon.js test? How do you make a cannon.js test? This script and codes were developed by Khalkeus on 11 November 2022, Friday.
Cannon.js test - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>cannon.js test</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src='https://cdnjs.cloudflare.com/ajax/libs/three.js/84/three.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/cannon.js/0.6.2/cannon.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Cannon.js test - Script Codes CSS Codes
body, html{ width: 100%; height: 100%; margin: 0px; padding: 0px; overflow: hidden;
}
Cannon.js test - Script Codes JS Codes
var camera, renderer, scene, world;
window.onload = function(){ init();
}
function randomFloat(a, b){ var r = (Math.random() * (b - a) + a); return r;
}
function init(){ renderer = new THREE.WebGLRenderer({antialias: true}); renderer.shadowMapEnabled = true; scene = new THREE.Scene(); camera = new THREE.PerspectiveCamera(20, window.innerWidth/window.innerHeight, 0.1, 1000); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement); camera.position.z = 100; camera.rotation.x = -.2; camera.position.y = 30; scene.background = new THREE.Color(0x000000); canvas = document.querySelector('#b canvas'); world = new CANNON.World(); world.gravity.set(0, -9.8, 0); world.broadphase = new CANNON.NaiveBroadphase(); var light = new THREE.AmbientLight(0x333355); scene.add(light) light = new THREE.DirectionalLight(0xffddaa); light.position.set(40, 100, 100); scene.add(light); light.castShadow = true; var groundShape = new CANNON.Box(new CANNON.Vec3(10, .5, 10)); var groundBody = new CANNON.Body({ mass: 0, shape: groundShape }); var plane = new THREE.Mesh(new THREE.BoxGeometry(20, .5, 20), new THREE.MeshPhongMaterial({color: 0x333333})); plane.position.y += .4; plane.receiveShadow = true; scene.add(plane); world.add(groundBody); render();
}
window.onresize = function(){ camera.aspect = window.innerWidth/window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight);
}
var cubes = [];
var maxCubes = 50;
var countDown = 0;
function render(){ renderer.render(scene, camera); world.step(.0166); if(countDown <= 0 && cubes.length < maxCubes){ var box = new CANNON.Box(new CANNON.Vec3(1, 1, 1)); var boxBody = new CANNON.Body({mass: randomFloat(1, 10), shape: box}); boxBody.position.set(randomFloat(-5, 5), randomFloat(30, 40), randomFloat(-5, 5)); world.add(boxBody); var boxImg = new THREE.Mesh(new THREE.BoxGeometry(2, 2, 2), new THREE.MeshPhongMaterial({color: Math.random()*0xFFFFFF<<0, emissive: 0x111111})); boxImg.castShadow = true; boxImg.receiveShadow = true; scene.add(boxImg); cubes.push([boxBody, boxImg]); countDown = 10; } for(var i = 0; i < cubes.length; i++){ cubes[i][1].position.set(cubes[i][0].position.x, cubes[i][0].position.y, cubes[i][0].position.z); } countDown--; scene.rotation.y += .01; requestAnimationFrame(render);
}
Developer | Khalkeus |
Username | khalkeus |
Uploaded | November 11, 2022 |
Rating | 3 |
Size | 2,524 Kb |
Views | 12,144 |
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 |
Soft | 2,727 Kb |
City generator | 2,750 Kb |
Boids ii | 3,358 Kb |
Random walkers | 2,512 Kb |
Metaballs | 2,277 Kb |
Flowers | 2,588 Kb |
Particle fire | 3,152 Kb |
Boids i | 3,564 Kb |
Boids iii | 2,947 Kb |
Rasterization | 3,615 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 |
Toolbar | Onsen | 5,414 Kb |
Myprofile | SoufianeAbid | 2,451 Kb |
Personal Logo Animation | Lloydwheeler | 3,795 Kb |
Css or Czz.. | Judag | 4,111 Kb |
Lightrays v2 | Sinthetyc | 2,903 Kb |
Buttons for autumn | Nikazawila | 1,795 Kb |
Spin | Elalemanyo | 8,262 Kb |
CSS Link Icons with jQuery Titles | Nicwinn | 2,312 Kb |
A Pen by Paul Sullivan | Pwsm50 | 2,349 Kb |
Simple Carousel Pure CSS | Dangvanthanh | 4,080 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!