Giter VIP home page Giter VIP logo

Comments (4)

donmccurdy avatar donmccurdy commented on July 28, 2024

Hi @thenayr — your code looks OK to me. Here's a similar example of my own, which does work. A common issue is getting the order of scripts right. Generally, you'll need:

<head>
  ...
  <!-- aframe.js -->
  <!-- aframe-physics-system.js and any other scripts registering components -->
</head>
<body>
...
<a-scene> ... </a-scene>
<script>
document.querySelector('a-scene').addEventListener('render-target-loaded', function () {
  // any code that appends things to the scene
});
</script>
</body>

Code that appends to the scene can also be put inside a component — in that case it should be included before the scene, with other components, as shown here.

from aframe-physics-system.

thenayr avatar thenayr commented on July 28, 2024

Thanks.

Looks like the key here was not setting the attribute dynamic-body prior to appending the element:

# Doesn't work
var box = document.createElement('a-box')
box.setAttribute('dynamic-body', '');
document.getElementById('myscene').appendChild(box)
# Does work
var box = document.createElement('a-box')
document.getElementById('myscene').appendChild(box)
box.setAttribute('dynamic-body', '');

Here is my React implementation (full disclosure, this code is probably gross):

import React from 'react';
import ReactDom from 'react-dom';
import {Entity} from 'aframe-react';

class Pod extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            name: props.name,
            color: props.color
        }
    }

    componentDidMount() {
        ReactDom.findDOMNode(this).setAttribute('dynamic-body', '');
    }

    render() {
        return(
            <Entity 
            id={`${this.state.name}`}
            key={`${this.state.name}`}
            geometry={{ primitive: 'box' }} 
            shape="box" 
            material={`color: ${this.state.color}; metalness:0.7`} >
                <Entity light={{type: 'point', color: '#63C7B2', intensity: '0.2'}} position="0 0 0" />
            </Entity>
        )
    }
}

export default Pod;

from aframe-physics-system.

jesstelford avatar jesstelford commented on July 28, 2024

Possibly related to: supermedium/aframe-react#43

from aframe-physics-system.

donmccurdy avatar donmccurdy commented on July 28, 2024

Not sure about react (some separate issues opened about that) but AFAIK physics is working ok with new entities now.

from aframe-physics-system.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.