flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > I search example fill boxes 3D triangle.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 2052
Roman 16 Mar 2026, 08:23
I want do simple voxelization 3D triangle. And search simple algorithm.
Filling all triangle square small boxes. Each box have size(XYZ) 0.1,0.1,0.1 and 3D position XYZ.
Get array boxes data.
And not using octree or k-tree.


Description:
Filesize: 83.22 KB
Viewed: 173 Time(s)

bandicam 2026-03-15 13-13-34-090.jpg


Post 16 Mar 2026, 08:23
View user's profile Send private message Reply with quote
pabloreda



Joined: 24 Jan 2007
Posts: 122
Location: Argentina
pabloreda 16 Mar 2026, 16:42
There's a very simple idea that works. I implemented it in the older version of my language.

The idea is to use the midpoint to find the voxels it touches and assign them the texture color at that location.
You have to be careful to ensure the midpoint calculation converges because you need to stop when the recursion returns the same point.

I generate an octree from the voxels, but when it's generated, it's just an array of voxels. To generate the octree, I order them using Morton's sort order, and this grouping is the octree itself.

Here's the code:

https://github.com/phreda4/r4/blob/master/r4/3d/voxobj.txt

the algo is

rectri(tri):
if tri == tri_ad → setvox
else:
M01 = midpoint(V0, V1)
M12 = midpoint(V1, V2)
M02 = midpoint(V0, V2)
rectri( tri(V0, M01, M02) )
rectri( tri(V1, M01, M12) )
rectri( tri(V2, M12, M02) )
rectri( tri(M01, M12, M02) )
Post 16 Mar 2026, 16:42
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 2052
Roman 17 Mar 2026, 14:47
I thinking Bresenham's line algorithm for 3D.
https://www.geeksforgeeks.org/python/bresenhams-algorithm-for-3-d-line-drawing/
And filling triangle many lines form boxes.

Bresenham's line algorithm for 2D very simple.
Post 17 Mar 2026, 14:47
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.