Answer the question
In order to leave comments, you need to log in
How to generate an image of 3D cubes (dice) on the server side?
On the server side, it is necessary to generate images with dice that "dropped out" randomly (rotation angle, projection angle, values on the faces - everything is random).
Unfortunately, I don’t know how to calculate the coordinates of points in the projection, I can’t implement it myself from scratch, so I’m looking for those who can do this.
I would very much like to implement it in PHP, but I am considering all options.
So far, only one solution has been found: www.fmwconcepts.com/imagemagick/3Dbox -- but I want alternatives.
I would be grateful for any hints and tips.
Answer the question
In order to leave comments, you need to log in
So far I have this idea:
the rendering of the image itself can be done by launching a headless browser in which a JS script with the Three.js library is executed . You just need to randomly position the camera and save the image of the object.
You have 2 ways: render in the browser but generate data on the server, or render on the server.
When throwing bones, what really matters is what is on the top faces, and the rest is largely unimportant. You need a little data, in fact an array with dropped bones.
In my opinion, it is most logical to render on the client using Three.js. Fortunately, drawing a cube with different faces is an elementary task. In threejs you can start with simple cubes and then draw a good model with materials in Fusion 360, export to STL, load the model into Three.js and animate it in space.
One way or another, you will come to the point that you want to have a colorful result. Such a result is possible only if there is control of lighting and surface materials. Those. you need the work of OpenGL or another graphics engine. This can be done in PHP https://github.com/Ponup/php-opengl The only question is overhead resources.
If you do not need to make a static identical picture, which will then be sent by mail, then there is no point in rendering on the server.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question