Cannon.js test

Developer
Size
2,524 Kb
Views
12,144

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 Previews

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);
}
Cannon.js test - Script Codes
Cannon.js test - Script Codes
Home Page Home
Developer Khalkeus
Username khalkeus
Uploaded November 11, 2022
Rating 3
Size 2,524 Kb
Views 12,144
Do you need developer help for Cannon.js test?

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!

Khalkeus (khalkeus) Script Codes
Name
Soft
City generator
Boids ii
Random walkers
Metaballs
Flowers
Particle fire
Boids i
Boids iii
Rasterization
Create amazing SEO content with AI!

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!