Is there a way to put a texture on a 3D Object?
-
I checked all over the code reference, but i couldn't find anything to help me. Has anyone made a function to put a texture on a 3D Object, or is it even possible?
-
I think @Gothon has done this a couple of times in his games. The way he does it is very complicated and involves a lot of math though. Unless you have taken and passed many highschool/college math classes, this is probably not the best option for you. I would just stick to the basic 3D models in Fuze's asset library.
-
The short answer is no there isn't. However there are a couple of ways to get around that limitation. The 3D 'terrain' object is unique in that you can assign color and height values to the vertices. Some people have been able to make simple low res textures with this object.
However if you want to take advantage Fuze's 2D image assets, 2D image editor and powerful image processing capabilities, you have to do everything in the 2D graphics mode. This means you must effectively make your own 3D engine. This is possible using functions like
drawQuad()
which allow you to draw a rectangular image with the corners at arbitrary positions. However there are various problems.drawQuad()
does not use a depth buffer and does not use 3D perspective correction.I shared a simple example of a rotating textured orthographic cube:
Texture Map Demo
ID:NX2H21QD9L
You can get a perspective scene if you limit rotations and draw walls and floors in strips which are at the same distance from the screen/camera. The classic technique of figuring out which wall is the closest and drawing that one is called ray-casting:
https://fuzearena.com/forum/topic/922/ray-castingAs time has gone on I have expieremented with various techniques most based on orthographic projection since I can draw a whole face in one command rather than looping over strips.
In 'Jump a Face' ID:
FUZEGJ0103
I changed the direction of the loop over the blocks so that they would draw in the right order. The sprite has to be positioned on the the same grid as a block tile or parts of it might not draw in the right order.In 'Green Whale' ID:
NXKKCGYD9L
I used a binary space partition tree (BSPT) which is a data structure that can determine the correct draw order for polygons. However to do this it has to be able to cut faces into pieces occasionally and this is expensive and complicated.In 'Mud Rover' ID:
RS763MND9L
I draw everything as a stack of 2D images ontop of each other as a 3D (voxel) bitmap. To do this I manually associate a light reflection normal with every pixel or voxel. I also have to limit rotation to a narrow range to keep from being able to see through the gaps in between the layers.Most recently 'SCULPTURE SURPRISE' ID:
NTV1VMND9L
I also draw a 3D (voxel) bitmap as stack of 2D images. However I have 3 different stacks (1 for each axis) so that you can rotate around without ever seeing a gap in the volume. Additionally I have a method that automatically computes the 3D light reflections using sophisticated image processing that works directly on the images without needing to know the geometry of the objects they represent.