Hello,
Trying to load a glb file with unLit texture, since I don’t need lighting on this model. Just flat colors…
how can I define this?
please help
Here’s the JS:
Blockquote
import * as THREE from ‘three’
import { OrbitControls } from ‘three/examples/jsm/controls/OrbitControls.js’
import * as dat from ‘dat.gui’
import { BufferGeometry, Loader, WireframeGeometry } from ‘three’
import { GLTFLoader } from ‘three/examples/jsm/loaders/GLTFLoader.js’;
// Debug
const gui = new dat.GUI()
// Canvas
const canvas = document.querySelector(‘canvas.webgl’)
// Scene
const scene = new THREE.Scene()
// Objects
const geometry = new THREE.TorusGeometry( .7, .2, 16, 100 )
//GLTF
const loader = new GLTFLoader()
loader.load(
// resource URL
‘assets/model.glb’,
// called when the resource is loaded
function ( gltf ) {
gltf.scene.scale.set(0.1,0.1,0.1);
gltf.scene.position.set(0,-2,0);
const load = gltf.scene;
scene.add(load);
// gltf.animations; // Array<THREE.AnimationClip>
// gltf.scene; // THREE.Group
// gltf.scenes; // Array<THREE.Group>
// gltf.cameras; // Array<THREE.Camera>
// gltf.asset; // Object
},
// called while loading is progressing
function ( xhr ) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},
// called when loading has errors
function ( error ) {
console.log( 'An error happened' );
}
);
const material = new THREE.MeshNormalMaterial;
material.color = new THREE.Color(0xff0000)
// Mesh
const ring = new THREE.Mesh(geometry,material)
ring.position.set (0,3,0);
scene.add(ring)
// Lights
const dirlight = new THREE.DirectionalLight(0xffffff, 0.9);
const pointLight = new THREE.PointLight(0xffffff, 0.5)
pointLight.position.x = 2
pointLight.position.y = 3
pointLight.position.z = 4
scene.add(pointLight)
scene.add(dirlight)
/**
- Sizes
*/
const sizes = {
width: window.innerWidth,
height: window.innerHeight
}
window.addEventListener(‘resize’, () =>
{
// Update sizes
sizes.width = window.innerWidth
sizes.height = window.innerHeight
// Update camera
camera.aspect = sizes.width / sizes.height
camera.updateProjectionMatrix()
// Update renderer
renderer.setSize(sizes.width, sizes.height)
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
})
const axes = new THREE.AxesHelper(5);
scene.add(axes)
/**
- Camera
*/
// Base camera
const camera = new THREE.PerspectiveCamera(75, sizes.width / sizes.height, 0.1, 100)
camera.position.x = 3
camera.position.y = 20
camera.position.z = 2
//camera.rotation.z = Math.PI / 5
scene.add(camera)
// Controls
const controls = new OrbitControls(camera, canvas)
controls.enableDamping = true
/**
- Renderer
*/
const renderer = new THREE.WebGLRenderer({
canvas: canvas
})
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.setSize(sizes.width, sizes.height)
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
renderer.shadowMap.enabled = true
const clock = new THREE.Clock()
const tick = () =>
{
const elapsedTime = clock.getElapsedTime()
// Update objects
ring.rotation.y = .5 * elapsedTime
// Update Orbital Controls
// controls.update()
// Render
renderer.render(scene, camera)
// Call tick again on the next frame
window.requestAnimationFrame(tick)
}
tick()