Utilized imported mesh in BABYLON's Mesh component

I'm encountering an issue with CSG on imported meshes. Here's the code snippet in question:

let x; let y;

BABYLON.SceneLoader.ImportMesh("", "./public/Models/", "model1.stl", scene, function (newMeshes) {
    // Set the camera target to the first imported mesh
    camera.target = newMeshes[0];
    x = newMeshes[0];
});



BABYLON.SceneLoader.ImportMesh("", "./public/Models/", "model2.stl", scene, function (newMeshes) {
    // Set the camera target to the first imported mesh
    //camera.target = newMeshes[0];
    y = newMeshes[0];
});


const xCSG = BABYLON.CSG.FromMesh(x);
const yCSG = BABYLON.CSG.FromMesh(y);

"x" and "y" are showing as undefined, with Debug pointing out that

 "BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh"

Is there a way to convert an imported mesh to BABYLON.MESH?

Thank you for your help!

Answer №1

In order to ensure the proper execution of ImportMesh, it is essential that your code resides within the callbacks section:

BABYLON.SceneLoader.ImportMesh("", "./public/Models/", "model1.stl", scene, function (newMeshes) {
    // Assign the first imported mesh as the camera target
    camera.target = newMeshes[0];
    a = newMeshes[0];
    
BABYLON.SceneLoader.ImportMesh("", "./public/Models/", "model2.stl", scene, function (newMeshes) {
    // Assign the first imported mesh as the camera target
    //camera.target = newMeshes[0];
    b = newMeshes[0];

var aCSG = BABYLON.CSG.FromMesh(a);
var bCSG = BABYLON.CSG.FromMesh(b);
});
});

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

What is the best way to implement media queries for mobile phones and desktop computers?

I've come across similar questions before but still can't wrap my head around it. Here's my dilemma: I want the index page of my website to display in desktop layout on desktops and mobile jquery on mobile devices. Currently, I have set up m ...

Why is this loop in jQuery executing twice?

$(document).bind("ready", function(){ // Looping through each "construct" tag $('construct').each( alert('running'); function () { // Extracting data var jC2_events = $(this).html().spl ...

Using JavaScript to auto-scroll a textarea to a certain position

Is there a way to change the cursor position in a textarea using JavaScript and automatically scroll the textarea so that the cursor is visible? I am currently using elem.selectionStart and elem.selectionEnd to move the cursor, but when it goes out of view ...

What is the best method for retrieving a child control from a TR element?

I am facing an issue with a hidden field inside each Tr in my template: <ItemTemplate> <tr style="" class="ui-selectee trClass ui-widget-content"> <td style="width: 100px"> <asp:HiddenField ID="idField" runat=" ...

Extract distinct values along with their respective counts from an array containing objects

Upon receiving a JSON request containing an array of objects with two properties, the task at hand is to extract the unique values along with their respective quantities. The following JSON data is being sent through Postman: [ {"name": "First value" ...

Update the text on a Button component using ReactJS

I am looking to update the text displayed on the Check All button to say Uncheck All after all the checkboxes have been checked. Below is my code. Any recommendations?” checkAllCheckBox = () => { let {todos} = this.state let newArray = [.. ...

Order JSON Array Using LoDash Library

Recently I encountered a JSON array with the following structure: var json = [ { key: 'firstName', value: 'Bill' }, { key: 'lastName', value: 'Mans' }, { key: 'phone', value: '123.456.7890&apo ...

Expandable full-width JavaScript accordion for seamless navigation

Currently, I am working on a simple on-page JavaScript application that consists of multiple data pages within one main page. My goal is to create a horizontal accordion effect where clicking on headers on either side will smoothly switch between the diffe ...

Guide to resizing and shifting to the right using CSS techniques

As a backend developer with experience in nodejs, I am diving into the world of web application development. HTML5 and CSS are new territories for me, but you can check out my small web application here. Now, I am looking to incorporate animations into my ...

Eliminating repeated duplication in the Geo Locate component of Leaflet React v3 with each refresh

I am currently working with Leaflet in React (v3) where adding components is necessary to render them on the map. The issue I am facing is that the output shows unwanted duplicate green circles that do not work on click as expected. Here is the image of th ...

Preventing an event from bubbling up to its parent in a jQuery Ajax call: A step-by-step guide

I am working on a page that showcases a tree list using unordered lists. Each li element with children triggers an ajax call to fetch those children and display them as another ul/li combination, which is functioning correctly. However, the problem arise ...

Choosing the relevant kendo row on two different pages

I am facing a situation where I have a Kendo grid displayed on a dashboard page. Whenever a user selects a row in this grid, I need to load the same row in another Kendo grid on a separate ticket page to showcase the details of that particular ticket. The ...

Encountering issues when attempting to establish the initial date of a react DatePicker based on the user's timezone

I am currently working on a React project and facing an issue with setting the default date of a DatePicker component to the user's timezone received from an API. Despite several attempts, I keep encountering an error whenever I try to inject the date ...

Unlocking the power of localhost on your mobile device

Currently, I am working on a web application that utilizes Laravel for APIs and React for the frontend. My goal is to test this application on a mobile device. While testing React in isolation works fine, I am encountering issues with backend data such a ...

"Transmit the document by utilizing the file ID in the form of

When sending a file from my server, I can easily define the path and it goes through successfully. However, with the node-telegram-bot-api, there is an option to send a document that is already hosted on telegram servers by providing the file_id in the doc ...

Incorporating Select2 into Your Laravel 4 Application

I've recently incorporated select2 into my multiselect search filter, but I'm struggling to integrate it effectively. Here's the method I'm using: public function getContactByName($name) { return Contact::select(array('id&apo ...

Ways to reset a JQuery/JavaScript filter

I am currently working on a list of div items that are being filtered and sorted using JavaScript. Each item animates as it enters the screen, scaling up to its final size. However, when I apply filters using buttons, items that are already displayed do n ...

Obtain product JSON using a product ID on Shopify

Looking to retrieve individual product JSON data based on the product ID https://testbydisnap.myshopify.com/products.json?product_id=10282991814 OR https://testbydisnap.myshopify.com/products/drummer-tshirt.js replace with https://testbydisnap.myshopi ...

Building a personalized payment experience using Python Flask and Stripe Checkout

I'm attempting to set up a customized checkout integration with Stripe on my Flask web application and I've encountered some issues. After copying the code from the Stripe documentation (located at https://stripe.com/docs/checkout#integration-cu ...

Is it possible to capture every ajax request?

My goal is to intercept all AJAX calls and check for specific error codes (ACCESS_DENIED, SYSTEM_ERROR, NOT_FOUND) in the response JSON sent from my PHP script. One approach I've seen is: $('.log').ajaxSuccess(function(e, xhr, settings) { ...