import "./styles/style.css";
import * as THREE from "three";
//Canvas
const container = document.getElementById("scene-container");
// constants
const FOV = 75;
const aspect = container.clientWidth / container.clientHeight;
const near = 0.1;
const far = 1000;
const height = window.innerHeight;
const width = window.innerWidth;
// Scene
const scene = new THREE.Scene();
scene.background = new THREE.Color("skyblue");
// Camera
const camera = new THREE.PerspectiveCamera(FOV, aspect, near, far);
camera.position.setZ(30)
camera.lookAt(0, 0, 0);
console.log(camera.position);
// Cube
const geometry = new THREE.BoxGeometry(2, 2, 2);
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00} );
const cube = new THREE.Mesh(geometry, material,1);
scene.add(cube);
console.log("cube spawned")
// Renderer
const renderer = new THREE.WebGLRenderer();
renderer.setSize(width ,height);
// Container
container.appendChild(renderer.domElement);
container.style.background = "black";
renderer.render(scene, camera);
#Mesh Not getting rendered
31 messages · Page 1 of 1 (latest)
Add a light to your scene like this
const light = new THREE.DirectionalLight(0xffffff, 1) light.position.set(0, 5, 3) scene.add(light)
I think MeshBasicMaterial does not require lightning
import "./styles/style.css";
import * as THREE from "three";
//Canvas
const container = document.getElementById("scene-container");
// constants
const FOV = 75;
const aspect = container.clientWidth / container.clientHeight;
const near = 0.1;
const far = 1000;
const height = window.innerHeight;
const width = window.innerWidth;
// Scene
const scene = new THREE.Scene();
scene.background = new THREE.Color("skyblue");
// Camera
const camera = new THREE.PerspectiveCamera(FOV, aspect, near, far);
camera.position.setZ(30)
camera.lookAt(0, 0, 0);
console.log(camera.position);
// Cube
const geometry = new THREE.BoxGeometry(2, 2, 2);
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00} );
const cube = new THREE.Mesh(geometry, material,1);
scene.add(cube);
console.log("cube spawned")
// Renderer
const renderer = new THREE.WebGLRenderer();
renderer.setSize(width ,height);
// Container
container.appendChild(renderer.domElement);
container.style.background = "black";
renderer.render(scene, camera);
use a animationFrame to render.
THANK YOU SO MUCH MAN !!
Working?
No I tried on a mac , a pc and this super but its still didn't work
On pc I downloaded a template and edited a little
That started working so I am good for now
But I'll keep the thread alove I still have no idea how that error can be solved
.
wdym class?
maybe css class that made the canvas show up
<canvas class="webgl"></canvas>
the webgl is required ,
after that it started working as usual
in the docs it is not written to include that class
which had me bamboozled
the docs did not had them tho
neither any you tuber that i watched
that's because it is not required
like, at all
but without it's not working
webgl class is likely defined in some css you copied from somewhere without knowing it is there 😔