Generate a new entity using a previously imported model with A-Frame

I have successfully imported a house model in .gltf format. I am now trying to extract the floor object from this model and turn it into its own individual a-frame entity for future reference. This is necessary so that I can designate the floor as the collisionEntity for the aframe-teleport-controls component.

Here is the current progress of my project:

AFRAME.registerComponent('floor-test', {
    schema: {
        floorname: {type: 'string', default: "floor"},
    },
    init: function () {
        this.el.addEventListener("model-loaded", (e) => {
            let child = this.el.object3D.getObjectByName(this.data.floorname, true);

            let floor = document.createElement("a-entity");
            floor.setObject3D("Object3D", child)
            floor.setAttribute("id", "floor")
            this.el.appendChild(floor)
        })
    }
});

This is how the aframe-teleport-controls entity looks like:

<a-mixin id="teleport" teleport-controls="type: parabolic; cameraRig: #cameraRig; collisionEntities: #floor "></a-mixin>

The floor object has been successfully created (although not yet positioned correctly), but the teleport controls are unable to recognize it as a collision entity.

How can I specify the 3D model's floor as the collision entity?

EDIT

Changing

floor.setObject3D("Object3D", child)
to floor.setObject3D("mesh", child) resolved the issue with the teleport collision entities.

However, the newly created floor object does not have the correct rotation.

I attempted to use the function

entityEl.object3D.getWorldRotation();
, as mentioned in the a-frame documentation, but it returns "0 0 0" instead of "0 180 0".

I also experimented with

THREE.SceneUtils.detach(child, parent, scene);
, but the child object did not appear in the scene.

Below is the updated code snippet:

AFRAME.registerComponent('floor-test', {
    schema: {
        floorname: {type: 'string', default: "floor"},
    },
    init: function () {
        this.el.addEventListener("model-loaded", (e)=> {
            let parent = this.el.object3D;
            let child = parent.getObjectByName(this.data.floorname, true);

            let floor = document.createElement("a-entity");
            floor.setObject3D("mesh", child)
            floor.setAttribute("id", "floor")
            floor.setAttribute("rotation", child.getWorldRotation())

            this.el.appendChild(floor)
        })
    }
});

Answer №1

It seems like there might be a timing issue with the teleport-controls being attached to the teleport mixin when the #floor element is missing. Since there is no 'refresh' method mentioned in the official documentation, there are a couple of ways to address this situation:

1) If the world is not dynamically generated, consider adding an invisible box at the floor location and treat it as Your #floor.

2) A more conventional approach would be to add the teleport-controls after the model has finished loading:

this.el.addEventListener("model-loaded", (e) => {
    let child = this.el.object3D.getObjectByName(this.data.floorname, true);

    let floor = document.createElement("a-entity");
    floor.setObject3D("Object3D", child)
    floor.setAttribute("id", "floor")
    this.el.appendChild(floor)
    let teleportEntity = document.querySelector("#teleport");
    teleportEntity.setAtrribute("type", "parabolic");
    teleportEntity.setAttribute("cameraRig", "#cameraRig");
    teleportEntity.setAttribute("collisionEntities", "#floor");
})


<a-mixin id="teleport"></a-mixin>

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

A scheduled task in Node.js set to run every day at 2 AM

My nodejs cron currently runs every 5 hours using the code below: cron.schedule("0 0 */5 * * *") How can I modify it to run daily at 2 AM instead? Thank you ...

jQuery template does not respond to input text when a click event is enabled on an iPhone device

Below is a jQuery template I have: <div class="parent-class"> <div class="sub-class"> <div clas="sub-input-class"> <input type="text" /> </div> </div> </div> Recently, I ...

Tips for transmitting an array of Objects to AngularJS

Summary I'm curious about how I can successfully send the following array of objects from NodeJS to an AngularJS app. var players = [ Footer: { username: 'Footer', hp: 200, exp: 1 }, Barter: { username: 'Barter', hp: 200, e ...

Unexpected behavior observed when trying to smoothly scroll to internal links within a div, indicating a potential problem related to CSS dimensions and

Within a series of nested div containers, I have one with the CSS property overflow:hidden. My goal is to smoothly scroll to internal links within this specific div using jQuery. The snippet of code below has worked successfully in previous projects: ...

Conditional compilation in Laravel Mix allows for specific code blocks to be

I'm currently working on a Laravel project and I need to introduce some conditional statements. Within the root folder of the project, there's a file called module_statuses.json which contains JSON variables like this: { "Module1": true, ...

The process of rendering children elements in React

I have a question about managing children components in React. While there are resources available explaining this concept, I believe a more detailed explanation would be helpful. Let's consider the structure of my React component tree, which looks l ...

Next.js threw a wrench in my plans when the HTML syntax was completely disrupted upon saving the index.js

I have encountered an issue in my VSCode environment while working on a next.js project. Whenever I attempt to save the index.js file, the HTML syntax crashes. I am at a loss on how to resolve this issue, so any assistance would be greatly appreciated. Tha ...

"By simply pressing the back button, Material UI Table effortlessly expands the row limit to accommodate

After creating a Material UI table and implementing Pagination, I noticed that the row limit increases automatically when clicking the back button. Even after consulting the Material UI docs, it seems like others are facing the same issue. Can anyone provi ...

React - output from forEach() function is not defined

I am facing a challenge in rendering prop values from a nested object. There are two issues that I'm encountering: 1. The JSX code line (with variables) is not showing up in the browser 2. When I console log the variables with .forEach() methods, th ...

Having difficulty adding a Dropdown Menu in a Pop-up Box

I am trying to incorporate a select menu inside of a popover, but every time I attempt to do so, the popover content block remains blank. The popover is associated with a side menu item called "Date History". Below is the code snippet I am using to constr ...

The useAutocomplete function in Material-UI fails to consider the disabled

Currently, I am working on developing my own Autocomplete component by utilizing the useAutocomplete hook from the mui/base package. Most parts of the implementation are functioning correctly, except for the disabled option. My expectation is that the com ...

What's the source of this undefined error and is there a way to eliminate it from the code?

After successfully filtering and reducing the data, I encountered an issue with undefined. I am trying to figure out what is causing this and how I can either remove it or make it visible on the screen without being invisible. You can also check the codes ...

Determine whether the user has scrolled past a specific threshold

Is there a way to display the button with the id backtotop only when the user has scrolled more than 250 pixels? This is my code: <template> <div> <button v-if="checkScroll" class="goTop" @click="backToT ...

Moving from the end to the beginning with a jQuery slider transition

Instead of relying on external plugins, I built this slider from scratch: function customSlider(selector, interval, index) { var slider = this; this.ind = index; this.selector = selector; this.slides = []; this.activeSlide = 0; this.amount; ...

Detecting URL changes, excluding just the hash, with JavaScript/jQuery

It's interesting to note that some websites are built using a "one-page system". In this type of system, when a user clicks on a link, the site doesn't take them to a new page but instead reloads the existing page with Ajax and updates the URL. ...

How to make the dropdown menu in Material UI Select have a horizontal scroll bar?

I've run into an issue in my project with the material ui Select component. The dropdown contents are too long and don't fit properly. https://i.sstatic.net/DNCTf.png To solve this problem, I tried adding a horizontal scroll to the dropdown men ...

Sending Twilio SMS Data from Node to React can be achieved by passing the post data

Currently utilizing Twilio for receiving SMS messages on my server, I am seeking a way to display the returned data in React. As Twilio sends data only server-side via a POST request when a text is sent from my phone, how can I access this POST data in m ...

Discovering the Newest Product Updates through API Integration

I have a component that displays only the most recent product fetched from an API: const about = ({products}) => { const data = products.attributes console.log(data) return ( <div> <h1>{data.Name}</h1> ...

The console log is displaying 'undefined' when trying to access Node.js fs

Recently, I was engrossed in developing a Next.js blog. After completing the frontend, I shifted my focus to building the backend using Next.js. ./pages/api I created a new file: ./pages/api/blogs.js To test my backend functionalities, I generated some J ...

Challenges arise in the grid system when implementing Material UI

Hey there, I've been trying to create card sets using material UI. I have organized the data from a JavaScript object, but unfortunately, the output is not what I expected. Below is the code I am currently using: const CardFeatures = () => { ...