<p>For each visible voxel side you need to iterate over all triangles and find if ray from voxel side normal intersects that particular triangle. Having intersection point you can then calculate <a href="https://mathworld.wolfram.com/BarycentricCoordinates.html" rel="nofollow noreferrer">barycentric</a> coordinates of this point within intersected triangle. And with barycentric coordinates you can calculate UV of intersection point and therefore sample color from original texture. If you need more than one pixel per voxel side then you can cast more rays.</p>

CC BY-SA 4.0
2021-01-13T22:26:30.143Z
This is really interesting. I'm definitely gonna give it a try; though it might take awhile, so I won't mark this question as answered quite yet. Thank you! May I ask where you gained this knowledge?
Simon Ward
CC BY-SA 4.0
2021-01-15T10:20:10.003Z
Most of engines return barycentric coordinates among other info when collsion test is requested, so you gain this knowledge wether you want it or not ;)
Sergio
CC BY-SA 4.0
2021-01-13T21:47:04.763Z
2021-01-13T21:47:04.763Z
Sergio
<p>everyone!
I am currently developing a program that converts a 3D model to 2D isometric pixel art. Part of my program extracts the texture from an FBX file (as FBX files can have textures built in), and then the texture will be used when converting to vox (which is then converted to a sprite sheet). So, I have a 3D model of a bed here:
<a href="https://i.sstatic.net/oTDmB.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/oTDmB.jpg" alt="bed model" /></a></p>
<p>And then I extract the texture programatically, which leaves us with a jpg:</p>
<p><a href="https://i.sstatic.net/3MX2O.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3MX2O.jpg" alt="bed texture" /></a></p>
<p>But then, when converting the 3D model to vox, I need to get the color from the specific locations on the bed where the model is being converted to voxels, to apply to each voxel. To do this, my thoughts are that I'll calculate where on this texture sheet would map to my current point on the 3D model, and get the color at that pixel.</p>
<p>The trouble is calculating this. My question is, how do I calculate how a 2D texture sheet is mapped to a 3D model? Thanks in advance for your answers!</p>

<3d><texture><mathematics>
Calculating Material/Texture Placement from Bitmap to 3D Model
Simon Ward
# Calculating Material/Texture Placement from Bitmap to 3D Model

(Asked by: username_0 on 2021-01-13)

everyone!
I am currently developing a program that converts a 3D model to 2D isometric pixel art. Part of my program extracts the texture from an FBX file (as FBX files can have textures built in), and then the texture will be used when converting to vox (which is then converted to a sprite sheet). So, I have a 3D model of a bed here:
[![bed model](https://i.sstatic.net/oTDmB.jpg)](https://i.sstatic.net/oTDmB.jpg)

And then I extract the texture programatically, which leaves us with a jpg:

[![bed texture](https://i.sstatic.net/3MX2O.jpg)](https://i.sstatic.net/3MX2O.jpg)

But then, when converting the 3D model to vox, I need to get the color from the specific locations on the bed where the model is being converted to voxels, to apply to each voxel. To do this, my thoughts are that I'll calculate where on this texture sheet would map to my current point on the 3D model, and get the color at that pixel.

The trouble is calculating this. My question is, how do I calculate how a 2D texture sheet is mapped to a 3D model? Thanks in advance for your answers!

**Tags:** 3d, texture, mathematics


---

## 1 answers

### Answer by username_1 on 2021-01-13. Score: 1 | Accepted answer

For each visible voxel side you need to iterate over all triangles and find if ray from voxel side normal intersects that particular triangle. Having intersection point you can then calculate [barycentric](https://mathworld.wolfram.com/BarycentricCoordinates.html) coordinates of this point within intersected triangle. And with barycentric coordinates you can calculate UV of intersection point and therefore sample color from original texture. If you need more than one pixel per voxel side then you can cast more rays.

> **Comments:**
> **username_0**: This is really interesting. I'm definitely gonna give it a try; though it might take awhile, so I won't mark this question as answered quite yet. Thank you! May I ask where you gained this knowledge?  
> **username_1**: Most of engines return barycentric coordinates among other info when collsion test is requested, so you gain this knowledge wether you want it or not ;)  

---

