diff --git a/package-lock.json b/package-lock.json index 6f1743e95..218ff5719 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "threejs-first-proj", + "name": "threejs-webpack-starter", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/src/script.js b/src/script.js index 9d86927ca..4c73b01e7 100644 --- a/src/script.js +++ b/src/script.js @@ -3,6 +3,12 @@ import * as THREE from 'three' import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js' import * as dat from 'dat.gui' +// Loading +const textureLoader=new THREE.textureLoader() + +const normalTexture = textureLoader.load("/textures.planet.jpg") + + // Debug const gui = new dat.GUI() @@ -13,12 +19,17 @@ const canvas = document.querySelector('canvas.webgl') const scene = new THREE.Scene() // Objects -const geometry = new THREE.TorusGeometry( .7, .2, 16, 100 ); +const geometry =new THREE.SphereBufferGeometry(.5,64,64) + // Materials -const material = new THREE.MeshBasicMaterial() -material.color = new THREE.Color(0xff0000) +const material = new THREE.MeshStandardMaterial() +material.roughness= 0.2 +material.metalness =0.7 +material.normalMap =normalTexture; +material.color = new THREE.Color(0x00ddbb) + // Mesh const sphere = new THREE.Mesh(geometry,material) @@ -73,11 +84,13 @@ scene.add(camera) * Renderer */ const renderer = new THREE.WebGLRenderer({ - canvas: canvas + canvas: canvas, + alpha: true }) renderer.setSize(sizes.width, sizes.height) renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)) + /** * Animate */ @@ -96,7 +109,7 @@ const tick = () => // controls.update() // Render - renderer.render(scene, camera) + renderer.render(scene, camera) // Call tick again on the next frame window.requestAnimationFrame(tick) diff --git a/src/style.css b/src/style.css index 70e4e1afa..88c9b59eb 100644 --- a/src/style.css +++ b/src/style.css @@ -6,7 +6,7 @@ html, body -{ +{background-color: darkolivegreen; height: 100vh; font-family: 'Poppins'; } diff --git a/static/Textures/planet.jpg b/static/Textures/planet.jpg new file mode 100644 index 000000000..d09f8b987 Binary files /dev/null and b/static/Textures/planet.jpg differ diff --git a/static/Textures/sci_fi_normal.jpg b/static/Textures/sci_fi_normal.jpg new file mode 100644 index 000000000..020bd680a Binary files /dev/null and b/static/Textures/sci_fi_normal.jpg differ