-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
50 lines (43 loc) · 1.69 KB
/
Copy pathscript.js
File metadata and controls
50 lines (43 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Initialize scene, camera, and renderer
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Add lighting
const light = new THREE.AmbientLight(0xffffff, 1);
scene.add(light);
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
scene.add(directionalLight);
// Function to get URL parameters (for Power BI integration)
function getParameterByName(name) {
let url = new URL(window.location.href);
return url.searchParams.get(name);
}
// Default model URL (loads this if no Power BI data is passed)
let modelURL = getParameterByName("model") || "models/sample.glb";
// Load the 3D model
const loader = new THREE.GLTFLoader();
loader.load(modelURL, function (gltf) {
const model = gltf.scene;
model.position.set(0, -50, 0); // Adjust model position
model.scale.set(1, 1, 1); // Adjust model scale if needed
scene.add(model);
console.log("✅ Model Loaded:", modelURL);
}, undefined, function (error) {
console.error("❌ Error loading model:", error);
});
// Set up camera position
camera.position.set(0, 100, 300);
// Animation loop
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
// Handle window resizing
window.addEventListener("resize", function () {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});