{"id":12835,"date":"2023-01-02T13:28:28","date_gmt":"2023-01-02T18:28:28","guid":{"rendered":"http:\/\/local.brightwhiz\/?post_type=snippets&p=12835"},"modified":"2023-01-02T13:28:30","modified_gmt":"2023-01-02T18:28:30","slug":"create-a-three-js-render-in-web-browser","status":"publish","type":"snippets","link":"http:\/\/local.brightwhiz\/snippets\/create-a-three-js-render-in-web-browser\/","title":{"rendered":"Create a Three.js Render in Web Browser Example"},"content":{"rendered":"\n
Create a Three.js render in web browser example code.<\/p>\n\n\n\n
import '.\/style.css'\nimport * as THREE from 'three'\n\n\/\/ Scene\nconst scene = new THREE.Scene()\n\n\/\/ Object\nconst geometry = new THREE.BoxGeometry(1, 1, 1)\nconst material = new THREE.MeshBasicMaterial({ color: 0xff0000 })\nconst mesh = new THREE.Mesh(geometry, material)\nscene.add(mesh)\n\n\/\/ Sizes\nconst sizes = {\n width: 800,\n height: 600\n}\n\n\/\/ Camera\nconst camera = new THREE.PerspectiveCamera(75, sizes.width \/ sizes.height)\ncamera.position.z = 3\nscene.add(camera)\n\n\/\/ Renderer\nconst renderer = new THREE.WebGLRenderer({\n canvas: document.querySelector('canvas.webgl')\n})\nrenderer.setSize(sizes.width, sizes.height)\nrenderer.render(scene, camera)<\/code><\/pre>\n","protected":false},"comment_status":"open","ping_status":"closed","template":"","meta":[],"categories":[953,23,25,27,15,16,18],"tags":[33,424,433,449,544,1215,591],"yoast_head":"\nCreate a Three.js Render in Web Browser Example Code [Snippet]<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n