Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Renderer in three js

//rendering all of the scene components into the canvas element. 
// define the renderer
  renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
  renderer.setPixelRatio(window.devicePixelRatio);
  renderer.setSize(window.innerWidth, window.innerHeight);

  // append the rendered to the dom
  document.body.appendChild(renderer.domElement);

  // render the scene
  renderer.render(scene, camera);
Comment

what is renderer in three.js

import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'

const scene = new THREE.Scene()

const camera = new THREE.PerspectiveCamera(
    75,
    window.innerWidth / window.innerHeight,
    0.1,
    1000
)
camera.position.z = 2

const renderer = new THREE.WebGLRenderer()
renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild(renderer.domElement)

new OrbitControls(camera, renderer.domElement)

const geometry = new THREE.BoxGeometry()
const material = new THREE.MeshBasicMaterial({
    color: 0x00ff00,
    wireframe: true,
})

const cube = new THREE.Mesh(geometry, material)
scene.add(cube)

window.addEventListener('resize', onWindowResize, false)
function onWindowResize() {
    camera.aspect = window.innerWidth / window.innerHeight
    camera.updateProjectionMatrix()
    renderer.setSize(window.innerWidth, window.innerHeight)
    render()
}

function animate() {
    requestAnimationFrame(animate)

    cube.rotation.x += 0.01
    cube.rotation.y += 0.01

    render()
}

function render() {
    renderer.render(scene, camera)
}

animate()
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript get hours and minutes from date 
Javascript :: remove package-lock.json from commit 
Javascript :: Print the third number from right 
Javascript :: infinite loop MenuItem MUI fixed onClick event 
Javascript :: re-resizable react example 
Javascript :: parse and stringify dom element in js 
Javascript :: Joining two arrays with lookup 
Javascript :: createTextRange code example 
Javascript :: calculate percentage in javascript 
Javascript :: react extends component App.defaultProps 
Javascript :: nodejs express parse query params boolean 
Javascript :: jquery for get object in 2nd or 3rd place 
Javascript :: react with routing parameter and active NavLink 
Javascript :: _.extend() Explanation 
Javascript :: CDNs for arquero 
Javascript :: how can we find location by using date in javascript 
Javascript :: hsv to rgb js 
Javascript :: mvc return view with query string 
Javascript :: kayengxiong promise js 
Javascript :: how to confirm if angular js in installed 
Javascript :: javascript object duplicate keys 
Javascript :: use prism to render markdown in next js with gray-matter 
Javascript :: increment number in for loop javascript 
Javascript :: javascript detect video change to muted 
Javascript :: limpiar historial angular 
Javascript :: setCount 
Javascript :: javascript flow function 
Javascript :: copy value from one sheet to anotehr 
Javascript :: for (i = 0; i < N; i++) for (j = 0; j < N; j++) { .... some O(1) code ... } 
Javascript :: javascript Check the answer 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =