My three.js practice

Size
3,203 Kb
Views
10,120

How do I make an my three.js practice?

What is a my three.js practice? How do you make a my three.js practice? This script and codes were developed by Esambino Wei Cheng Hsieh on 07 January 2023, Saturday.

My three.js practice Previews

My three.js practice - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>my three.js practice</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r61/three.min.js"></script>
<body></body> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

My three.js practice - Script Codes CSS Codes

body{ background-color:#222;
}
canvas { width:100%; height:100%;
}

My three.js practice - Script Codes JS Codes

var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
/* In addition to creating the renderer instance, we also need to set the size at which we want it to render our app. It's a good idea to use the width and height of the area we want to fill with our game - in this case, the width and height of the browser window. For performance intensive games, you can also give setSize smaller values, like window.innerWidth/2 and window.innerHeight/2, for half the resolution. This does not mean that the game will only fill half the window, but rather look a bit blurry and scaled up. Last but not least, we add the renderer element to our HTML document. This is a <canvas> element the renderer uses to display the scene to us.
*/
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
/* Create Lights: PointLight / SpotLight etc.*/
var spotLight = new THREE.SpotLight(0xffffff);
spotLight.position.set(100,100,100);
spotLight.castShadow = true; //If set to true light will cast dynamic shadows. Warning: This is expensive and requires tweaking to get shadows looking right.
spotLight.shadowMapWidth = 1024;
spotLight.shadowMapHeight = 1024;
spotLight.shadowCameraNear = 500;
spotLight.shadowCameraFar = 4000;
spotLight.shadowCameraFov = 30;
scene.add(spotLight);
/* Create Material */
function Mat(){ var material = new THREE.MeshPhongMaterial({ color : new THREE.Color("rgb(35,35,213)"), //Diffuse color of the material emissive : new THREE.Color("rgb(64,128,255)"), //Emissive(light) color of the material, essentially a solid color unaffected by other lighting. Default is black. specular : new THREE.Color("rgb(93,195,255)"), /*Specular color of the material, i.e., how shiny the material is and the color of its shine. Setting this the same color as the diffuse value (times some intensity) makes the material more metallic-looking; setting this to some gray makes the material look more plastic. Default is dark gray.*/ shininess : 1, //How shiny the specular highlight is; a higher value gives a sharper highlight. Default is 30. shading : THREE.FlatShading, //How the triangles of a curved surface are rendered: THREE.SmoothShading, THREE.FlatShading, THREE.NoShading wireframe : 1, //THREE.Math.randInt(0,1) transparent: 1, opacity : 0.15 //THREE.Math.randFloat(0,1) }); return material;
}
/* Create Geometry */
var geometry = new THREE.SphereGeometry(50,20,20,0,Math.PI*2,0,Math.PI);
//SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength)
/* Create Earth Sphere*/
var earth = new THREE.Mesh(geometry, Mat());
/*
var numSphere = 30;
var tabSphere = [];
for(var i=0: i<numSphere; i++){ tabShpere.push(new Sphere(i)); scene.add(tabSphere[i].b);
}
*/
scene.add(earth);
camera.position.z = 90;
/* This will create a loop that causes the renderer to draw the scene 60 times per second. If you're new to writing games in the browser, you might say "why don't we just create a setInterval? The thing is - we could, but requestAnimationFrame has a number of advantages. Perhaps the most important one is that it pauses when the user navigates to another browser tab, hence not wasting their precious processing power and battery life.
*/
function render(){ requestAnimationFrame(render); earth.rotation.x += 0.01; earth.rotation.y += 0.01; renderer.render(scene, camera);
}
render();
My three.js practice - Script Codes
My three.js practice - Script Codes
Home Page Home
Developer Esambino Wei Cheng Hsieh
Username Esambino
Uploaded January 07, 2023
Rating 4.5
Size 3,203 Kb
Views 10,120
Do you need developer help for My three.js practice?

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!

Esambino Wei Cheng Hsieh (Esambino) Script Codes
Name
Scroll
Practice hover
CSS3 Latte Art Logo
Cafe Lakulaku
Three test
Present Box
Addthis_button
CSS3 Slider Practice
Gdf
Blank
Create amazing Facebook ads 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!