supermedium / aframe-react

:atom: Build virtual reality experiences with A-Frame and React.
https://ngokevin.github.io/aframe-react-boilerplate/
MIT License
1.42k stars 151 forks source link

Do not discard non-component properties when using primitives #50

Closed jsantell closed 7 years ago

jsantell commented 7 years ago

Hacking on a short hand library for using aframe react's primitives in aframe-react-components. Essentially mapping:

<Sphere radius={5} /> to <Entity primitive='a-sphere' radius={5} /> which should map to <a-sphere radius='5' />

But currently, the short hand properties provided by primitives are discarded, requiring a user to define with the full component mapping, like <Entity primitive='a-sphere' geometry={{ radius: 5 }} />.

Is it possible to know these mappings for stock primitives? Dug around a bit, and couldn't seem to find a way to expose these via the AFRAME global. Still new to aframe-react, so I might be missing something, but if this sounds good (and it's possible to get these mappings), I'll work on a PR

jsantell commented 7 years ago

Possibly similar to #49

ngokevin commented 7 years ago

Ah, that's a nasty bug.

There should be like AFRAME.primitives['a-box'].mappings, but maybe we can just skip that check altogether?

jsantell commented 7 years ago

The objects stored at AFRAME.primitives.primitives['a-box'] seem to only be the constructor, although geometries expose their schema AFRAME.geometries.box.schema which could get us close to just acknowledging valid properties (since Aframe handles the mapping anyway), but this would only work for primitives based on geometry, not things like <a-cursor> or <a-camera>. I'll hack on some solutions

ngokevin commented 7 years ago

Might be simple to remove the check for invalid properties. A-Frame will handle raising warnings about that.

jhsu commented 7 years ago

instead of returning an <Entity /> the library could just return a React.createElement, that way there's no prop proxying needed. Essentially treating the primitive as a normal dom element.

see: https://github.com/jsantell/aframe-react-components/pull/1

ngokevin commented 7 years ago

Primitives can also take components, which needs the layer of serialization that converts objects passed as props to strings that HTML can understand.

jhsu commented 7 years ago

that's right...

ngokevin commented 7 years ago

Fixed in v4.0.x. Nothing being discarded now, everything is sent thru .setAttribute().