I am working in OutSystems ODC (cloud) and need a sample implementation file that demonstrates how to integrate Three.js. . The goal is to load and display a GLTF model as a 3D view within an ODC screen. anyone help me to provide sample OML file
To integrate Three.js and display GLTF 3D models in OutSystems ODC, you need to import the Three.js library, load the GLTF file dynamically, and display the model using a block or screen. Below are the step-by-step instructions:
.js
wwwroot/scripts/
canvas
3DCanvasContainer
OnReady
Below is a sample script for handling Three.js within your Block:
// Initialize Three.js Scene const container = document.getElementById($parameters.WidgetId); const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera(75, container.offsetWidth / container.offsetHeight, 0.1, 1000); const renderer = new THREE.WebGLRenderer(); renderer.setSize(container.offsetWidth, container.offsetHeight); container.appendChild(renderer.domElement); // Load GLTF Model const loader = new THREE.GLTFLoader(); loader.load( 'path-to-your-gltf-model/model.gltf', // Replace with your model URL function (gltf) { scene.add(gltf.scene); }, function (xhr) { console.log((xhr.loaded / xhr.total * 100) + '% loaded'); }, function (error) { console.error('An error happened while loading the model.', error); } ); // Add Lights const light = new THREE.AmbientLight(0xffffff, 0.5); scene.add(light); // Set Camera Position camera.position.z = 5; // Animation Loop const animate = function () { requestAnimationFrame(animate); renderer.render(scene, camera); }; animate();
In the block, define input parameters such as:
WidgetId
ModelURL
Use ${parameters.ModelURL} to dynamically set the model's path within the script.
${parameters.ModelURL}
Id
Preview the application to ensure the 3D model loads correctly and the canvas is appropriately rendered within the screen dimensions.
For additional usage of JavaScript dependencies and integration details, you can explore OutSystems Front-End Deepdive: Tips and Tricks.
This implementation ensures modularity and reusability of your 3D viewer component across multiple screens in OutSystems ODC. Let me know if you need further clarification or enhancements!