DEV Community

Discussion on: How to Create a 3D Cube in ReactJS 🧊

Collapse
 
icecoffee profile image
Atulit Anand

Thanks a lot :)

Collapse
 
maxinejs profile image
Maxine

Always!

Collapse
 
rachaelsmathew profile image
Rachael Mathew

Hi, how would you create a cube that only spins/moves left or right(can only be rotated on the xz plane)?
Also, is there a wy to set a default position of the cube(ie. cube is tilted slightly downward, or cube is faced straight ahead) for when the web page has loaded?

Thread Thread
 
maxinejs profile image
Maxine

The answer to both those questions is yes. Unfortunately I don't have an answer as to how to do it right this second, but I would like to revisit this soon and figure that out myself. Until then my best guess would be css .cube classes and playing around with the transform, rotate, translate. Hope that helps!

Thread Thread
 
rachaelsmathew profile image
Rachael Mathew

Hi, Thank you for your response! However, I am not able to rotate the cube on mobile devices, do you know anything about this?

Thread Thread
 
maxinejs profile image
Maxine

(I am not 100% positive on this) but I believe it’s just limitations with react-3D-cube unfortunately. I believe you can use three.js. If not unfortunately the only other way I know of is getting funky with css transform 3dtransfrom, and 3drotate properties. I hope this helps a little bit!

Thread Thread
 
icecoffee profile image
Atulit Anand

Since their is no documentation provided by the author on npm package. I dont think this package supports any such feature but you can always modify the original code to get things done your way.

My opinion is to check out documentation of motion js and then take a look at line 230 in cube.tsx πŸ‘‡
github.com/pjb0811/react-3d-cube/b...

Thread Thread
 
maxinejs profile image
Maxine

Thank you for coming through!!!