What is the best way to extract the geometry information from a gltf object?

I've been using three.js to load a gltf file with the gltfloader, and now I'm trying to create a particle system. However, I'm having trouble getting the geometry object that I need.

function initModel() {

    var planeGeometry = new THREE.PlaneGeometry(100, 100);
    var planeMaterial = new THREE.MeshLambertMaterial({color: 0xaaaaaa, 
    side: THREE.DoubleSide});
    var plane = new THREE.Mesh(planeGeometry, planeMaterial);
    plane.rotation.x = -0.5 * Math.PI;
    plane.position.y = -.1;
    plane.receiveShadow = true; 
    scene.add(plane);

    var loader = new THREE.GLTFLoader();
    loader.load('./../model/scene.gltf', function (gltf) {  
        gltf.scene.scale.set(10,10,10);
        //I'm stuck on how to access the geometry object here

    });


}

Answer №1

To locate the mesh within the model, you can either traverse through the structure or utilize getObjectByName(MeshName) function if you already know the name of the mesh. Then, extract the geometry from the identified mesh. For instance:

var geometry = getObjectByName('Plane001').geometry;

Assuming the mesh is named Plane001.

I have devised a straightforward helper method for retrieving all children of a specific type from an object

findType(object, type) {
    object.children.forEach((child) => {
        if (child.type === type) {
            console.log(child);
        }
        this.findType(child, type);
    });
}

Subsequently, I would invoke findType(gltf.scene, 'Mesh') from the loader to display all meshes in the model

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Make sure to update the package.json file at multiple locations following the execution of the "npm i" command

My goal is to automatically detect any newly installed packages based on my package.json file. This way, whenever I run "npm i", the new package will be added not only to the usual "dependencies" section but also to a custom section called "extDependenci ...

Using ThreeJS to project a mouse click onto the XZ plane

I am currently working on implementing offline routing in a 3D map within a ThreeJS scene. My goal is to allow the user to click on a point and have a cube navigate to that point. While the navigation functionality is working correctly, I am facing an issu ...

Ways to conceal the header and footer on specific React pages

I currently have my header and footer wrapping the content on all pages of my website. However, I am looking to hide the header and footer on specific pages like the customer and admin dashboard. Can anyone suggest the best approach to achieve this? cons ...

Tips for extracting certain characters from a URL and saving them as an ID using JavaScript

Consider this scenario where I have a specific URL: http://localhost:3000/legone/survey/surveyform/form11/03141800300000030001 In order to achieve the desired outcome, I aim to extract and store different parts of the URL into designated IDs. Specificall ...

What is the best way to export assets into a React Native JS file?

After watching a video on YouTube, I noticed that at 3:20 the individual in the video quickly exported multiple assets into a file without providing any explanation. Can someone please view this specific moment in the video and clarify how this person mana ...

Discover the steps to retrieve a fresh array in PHP after utilizing sortable.js

Hi there! I am currently utilizing the sortable javascript feature found on Although the script is working perfectly fine for me, being a non-expert in javascript poses a challenge when it comes to generating the necessary code to retrieve an array in php ...

Each time the page is reloaded, an error message pops up: "TypeError: Cannot access attributes of an undefined object (referencing 'name')."

Everything seems to be working fine in my app, except for one issue when I try to refresh the page where an event is being edited (EditEvent Component). The error message I receive is: Uncaught TypeError: Cannot read properties of undefined (reading ' ...

Identifying Touch Interaction exclusively on WebGL Canvas within threejs

Currently, I am developing a threejs application that requires input from HTML buttons and utilizes Raycast Detection on touch within threeJS. The issue I am encountering is that when the user clicks an HTML button, the Raycast function is triggered as we ...

Dynamic website where each page is loaded based on the user's previous interaction

Can I get your opinion on something? I'm currently working on an ajax webpage. The links on my page make a GET request to the URL they are linked to, extract the div.content, and then update the content of the current div.content. Strangely, this GET ...

Controlling the Flow of Events in JavaScript Documents

Explore the integration of two interconnected Javascript files and delve into managing event propagation between them effectively. 1st js file var red = [0, 100, 63]; var orange = [40, 100, 60]; var green = [75, 100, 40]; var blue = [196, 77, 55]; var ...

What is the process of importing a file as text into vite.config.js?

Within my project directory, there is a simple SCSS file that I need to access its content during the compilation process in order to transform it in vite.config.js. However, I am unsure of how to retrieve its content. I have successfully obtained the cont ...

Updating Angular Material theme variables during the build processIs this okay?

How can I easily customize the primary color of my angular 6 application to be different for development and production builds? Is there a simple solution to automatically change the primary color based on the build? ...

Is there a Facebook application embedded in the user's wall?

Is it feasible to create a website similar to YouTube, where users can share it on Facebook and run the app (in this case, the video player) directly on their wall without having to visit the YouTube page? If it is possible, is this functionality limited ...

Incorporate concealed image into HTML

When I perform actions with a couple of images, I encounter delays because the browser needs to load the images. For example, if I use $('body').append(''); everything works smoothly without any delays. However, when I try using style= ...

Utilize an external JavaScript file function within an AngularJS controller

I have an external JavaScript file with additional functions that I am trying to call from an Angular controller. Here is an example of the external.js file: ... ... function fun() { ... ... } ... ... The controller in question is called acccountCon ...

Unable to delete a dynamically inserted <select> element by using the removeChild method

As someone who is new to coding web applications, I am currently working on a project that involves adding and deleting dropdowns dynamically. Unfortunately, I have run into an issue where the delete function does not work when the button is pressed. Her ...

Utilizing Unidirectional Binding within an AngularJS Directive

I have a directive set up here: myApp.directive('stoplight', function() { return { restrict:'E', transclude: true, scope: { value: '@' }, link: function(scope, element) ...

What is the best way to delete the material-dashboard-react text from the starting route in a material ui admin panel?

When launching my React web application, I am initially directed to localhost:3000/material-dashboard-react, which then redirects to /. However, this redirect is briefly visible before the web app fully loads. Can anyone advise on how to remove this initia ...

Incorporating jquery.prettyPhoto results in the script being displayed on the webpage

When I relocate the following script: <script src="js/jquery.prettyPhoto.js"></script> To this location: <script type="text/javascript"> ... </script> The script starts displaying on the page starting from the bold section on ...

Currently seeking user coordinates for Vue implementation

I recently started using Vue and I'm working on capturing the lat/long of a user to be used in other functions within Vue. Currently, I am retrieving the coordinates and plan to utilize them in an API but for now, I am just logging them. Although I c ...