Hi,
I am new to this forum and to three.js.
try to bring three.js to work. Uploaded the used model to a gltf viewer and the uploaded folder with the gltf the .bin and the .png worked like a charm.
so it is my code.
Any observations?
Thanks
Tristan
<!DOCTYPE html>
<html>
<head>
<title>Aluminum Material Example</title>
<style>
body { margin: 0; overflow: hidden; }
canvas { display: block; }
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r117/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.131.2/examples/js/loaders/GLTFLoader.js"></script>
<script src="https://cdn.jsdelivr.net/gh/mrdoob/three.js@r117/examples/js/controls/OrbitControls.js"></script>
<script>
// Set up the scene, camera, and renderer
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Load the GLTF model
var loader = new THREE.GLTFLoader();
var textureLoader = new THREE.TextureLoader();
var modelPath = 'models/RB250-CL2.gltf';
var basePath = modelPath.substring(0, modelPath.lastIndexOf('/') + 1);
loader.load(modelPath, function (gltf) {
gltf.scene.traverse(function (child) {
if (child.isMesh) {
// Set up the material
var material = new THREE.MeshStandardMaterial({
color: 0xCCCCCC,
metalness: 1,
roughness: 0.4
});
// Set up the texture
var texturePath = basePath + 'RB250-CL2_images/composited_baseColor_opacity.png';
var texture = textureLoader.load(texturePath);
material.map = texture;
child.material = material;
}
});
scene.add(gltf.scene);
});
// Set up the camera position
camera.position.z = 5;
// Set up the controls
var controls = new THREE.OrbitControls(camera, renderer.domElement);
// Render the scene
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
controls.update(); // Update the controls
}
animate();
</script>
</body>
</html>