Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Has anybody coded uv cube mapping? Any ideas? Resources?

Author
Message
SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 23rd Dec 2011 23:50
As the title says....

Im looking for some help with programming UV Cube mapping to apply to vertex uv,s

I have managed to find code for sphere mapping, I coded plane mapping easy....just stuck on cube mapping for some reason..

If anyone can point me in the right direction that would be great

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Dec 2011 00:15
I'm not too sure about DBPro native cube mapping, but, in a shader, cube mapping usually uses a direction vector such as the normal or reflection vectors to look up the cube map texture.

The basic idea is as follows.

Imagine the six faces of a cube textured with the six component images of the cube map. Then each possible normal vector direction will point to a single point on the cube's surface if you imagine the vector pointing away from the centre of the cube. The direction vectors used for this in a shader don't need to be normalised which saves a bit of computation.

This probably means that your objects will need to have normals included in the vertex format (FVF) - which standard DBPro objects will have by default.

I haven't got DBPro here but if I recall correctly the built-in cube mapping command will need 6 images representing the six faces of the cube map. If you're using a shader you'll probably want these combined into a single cube map image which will be one of the available DDS image file formats.
SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 24th Dec 2011 01:32
i seen you did some code a while ago that set normals... I did some looking on the internet and your code is actualy the building blocks of setting uv data but needs a tad extra calc done.

Using your code i have partialy coded a sphere mapping calc....but its a tad off.



I will probably go ahead with a release without cube mapping but it sure would be a nice addition.

Here is what i've done with your code to semi calc out sphere mapping.....but again something is still off with it. The easiest was the plane mapping.


Im sure you will recognize that code :p by the way works very well for calcing normals :p

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 24th Dec 2011 02:02
Hi there...I would like to guess that question too. In my Lathe Tool program, I had to make my own function to texture the complete lathe with a full texture. When we use set vertexdata UV, it applies to the object a flat texture depending on the vertexdata position in axis x,y or z,y or x,z. So I had to use scale texture and scroll texture command to fine tuning. I don't know how we could apply a revolve texture to cylinder that hasn't uv using vertexdata commands.

Cheers.

basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 24th Dec 2011 02:45 Edited at: 24th Dec 2011 23:31
by the way, you can apply the sphere mapping on any object.

cube mapping: set cube mapping on objno,img1,img2,img3,img4,img5,img6

I still think this is not the answer for your question.
SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 24th Dec 2011 08:18 Edited at: 24th Dec 2011 08:27
no cube mapping is a different effect completely......

What im looking at doing is setting the first uv data to a newly created mesh that has no uv data. Even a cube map applied would not work without some sort of uv in the object already. All my values start at 0,0 wich means i wouldnt be able to apply any texture to the object whatso ever.

But thanks for trying to help

The objects you see in the image have had there uv completely deleted to test my new uv mapping functions and it looks to be working somewhat for the sphere mapping wich i thought would be the hardest one to code.....but looks like cube mapping will be the toughest afterall.

Ill give you an even better idea what im after....here is a screenshot of 3dsmax and how it lets you apply different types of uv data to a mesh.



Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Dec 2011 14:00
Quote: "no cube mapping is a different effect completely......
"


So what do you mean by this in your first post?

Quote: "Im looking for some help with programming UV Cube mapping to apply to vertex uv,s"


What exactly is "UV cube mapping"? Do you just mean UV mapping?
cyril
18
Years of Service
User Offline
Joined: 6th Aug 2007
Location: 7 miles away from big ben
Posted: 24th Dec 2011 14:17 Edited at: 24th Dec 2011 14:22
The correct name is "Cubic UV projection"(well thats what it is called in truespace at least)

It's the exact same UV type applied on a DarkBasic cube and SMD_3D Interactive's example above. What he is after is the same function to be usable in his program for any object.

When Cube UV projection is used on a per concave limb on a mesh, it makes it very easy to modify it for a proper surface UV mapping if you separate the projection faces of the UV cube regardless of poly count.

Edit: Sorry I don't have much of an idea of how I would code such a system, but I believe you might be able to access and change UV information using Vertex and/or Memblock Command sets.
SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 24th Dec 2011 17:32
yeah i wasnt sure if it had the same name or not.... thats why the title says uv cube mapping or in 3ds's case is uv box mapping.

SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 26th Dec 2011 22:29
ok well i guess i may be on my own for this one.....i've had to figure out tougher things i guess.....if i manage to code it i will share :p

cheers!

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Dec 2011 01:03
Thanks for the clarification.

In your screenshot can any texture be used? It looks to me as if the texture needs to be specially constructed/aligned to ensure that the edges line up.
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 29th Dec 2011 02:14 Edited at: 29th Dec 2011 02:16
Quote: "can any texture be used? It looks to me as if the texture needs to be specially constructed"


Not necesary, but if the image is seamlees the best. All 3D programs, has differents ways to add the mapping to the object...planar, cylindrical, box, spherical and even every face. All primitives has automatically mapping coords, but what about if we want our sphere to have planar or cylindrical mapping ?. As we all know, an image stars in the upper lefts and ends in lower rights....so how to add mapping coords to an object that has not mapping coords . In my lathe tool, I had to guess how to add the texture to every triangle correctly, in order to have a single texture in the whole object...I didn't know how many control points will decide the user to do to make its lathe, so I made a simple calculation in a ring of 18 triangles. Take a look to this piece of code.Use one of your textures.




As we are creating a new object made up of triangle, we have to think first, how to texture just a simple triangle, and how to scale the texture as we add more triangles(limbs) to the main object. I hope it can help someone.





Cheers.



I'm not a grumpy grandpa
SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 29th Dec 2011 06:04 Edited at: 29th Dec 2011 06:13
thanks for the screenshot!

Exactly what im after too!


The image does not need to be any specific size as a texture is uv mapped to a percentage of that image. so i could have an image 512x256 and still have a uv range of 0.0 to 1.0 for both u and v.

Chafari are you mostly after cylinder mapping for your lathe tool? I think i can whip up some code for that one but if there is a top or bottom face that is flat it will not work for what i have in mind.

How about this...
1. Find the highiest vertex and the lowest on the y axis.
2. create an object box to use for a pointing angle locator.
3. position this object in the center of all your vertex points.
4. point the object at each vertex (1 at a time to get the y angle from the center object.
5. devide your y angle by 360 to get a value between 0.0 and 1
6. Use the percentage of the y hieght from the highest point to the lowest to solve for v
7. set vertexdata uv (angle y/360), (percentage of vertex position y from the highest point to lowest point that you should be able to calculate a percentage on)

run through ever vert and try it? it might work.

But again will not fully work if you have a top face or a bottom face that is flat. You could always try to code plane mapping but you will get an edge that looks like this picture here:






you will get that funny look on a flat surface as well as the stretch look where the image starts and finishes.

Id be tempted to get something working for a cylinder type map. I will give it a try and see what i come up with. Maby i can do some calculations to find the flat surfaces to align the texture up differently for those faces.

SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 29th Dec 2011 06:20 Edited at: 29th Dec 2011 06:26
code for plane mapping (un scaled and stretches if nessesary)



(this is a section pulled from modelprop)
Depending on how you want the image to align you can lock 2 of the settings and just use one of them. If you leave it open the way it is it will default to using the z axis for applying the uv plane data

SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 29th Dec 2011 06:26 Edited at: 29th Dec 2011 07:00
Now sphere mapping i dont have it correctly but it looks like it may be doing something differently anyways....maby someone can point out a fix for it. This code was mostly copied over from Green Gandalf's setting normals example... (at least i think it was yours?) But play around with this code and you may get it to work better then i have. I also noticed it works better if you have more verts.


(Ians matrix dlls required)


(code extracted from modelprop)

Again...play with this and see if you can get it to work better then i have. I also know if you play with the angle 180 you can get the image looped on the object more frequent.

Here is the screen shot of the sphere mapping code above....all object mapped with the same code un modified. Only difference is the shapes or more vertexes.



Also should give this a read:
http://www.mvps.org/directx/articles/spheremap.htm

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 29th Dec 2011 11:30 Edited at: 29th Dec 2011 11:31
@SMD_3D Interactive
Thanks for the codes and the link.

Quote: "Chafari are you mostly after cylinder mapping for your lathe tool?"


At the moment, I have solved as I mention above, but I know that there must be a correct automatic formula.

I'v seen your method, and I can't undestand some bits of code

Quote: "if maxx#<get vertexdata position x(c) then maxx#=get vertexdata position x(c)"


I rem most of lines and the result is exactly the same .




Your code nearly works but there's something odd. In a cylindrical maping, we have to see just one image, and it gives two....like planar method. I will try to find out a better solution, and come back.

Cheers.

I'm not a grumpy grandpa
SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 29th Dec 2011 15:13 Edited at: 29th Dec 2011 15:15
yeah you cant rem the code that finds the center point....lol


Quote: "if maxx#<get vertexdata position x(c) then maxx#=get vertexdata position x(c)""

the initial start value for max x =0.0
i then run through all the verts.... and say if the vertex x position is greater then the max x vertex should equal that point

again its just to find the outside boundry's of the object.

this way you can calculate the center of your object as well as the width/height/depth of it.

notice there are 6 of these
max x
min x
max y
min y
max z
min z

then a have another code in there to get the total distance on each

distx#=maxx#-minx#
disty#=maxy#-miny#
distz#=maxz#-minz#


notice this is used to calculate the uv data
set vector3 1, avrx#/vertcnt, avry#/vertcnt, avrz#/vertcnt

ah actualy that code was used for the plane mapping and can be removed yes......except the average stuff. I now see your using the sphere mapping tecnique.

you need these back in!!
initial values=0 and then this

avrx#=avrx#+get vertexdata position x(c)
avry#=avry#+get vertexdata position y(c)
avrz#=avrz#+get vertexdata position z(c)

to gather all the points....


set vector3 1, avrx#/vertcnt, avry#/vertcnt, avrz#/vertcnt

and that sets the center of your object so this is a must as well!

SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 29th Dec 2011 15:18 Edited at: 29th Dec 2011 15:24
Doh!!

I just remembered.... if you save the object and reload it darkbasic tends to not save your new settings. it will revert back to the original uv data and would need to be set each time.

Would you like the specs for my .3mp format?

Let me know as i found i needed to save out all the raw data to a file other than dbp cause any changes did not save with it.

example file:


I could write everyone some generic code for saving to my format if you like and reconstructing it.

This is how model prop saves and loads as well as making it capable of converting to .x and back to .dbo properly

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 29th Dec 2011 20:06
@SMD_3D Interactive
Quote: "yeah you cant rem the code that finds the center point....lol"


What I meant , I execute your code in any object and the final result is the same with all lines of code as without those lines I rem.

If we have a box let's say size 10*10 and we make a mesh from itself and then we add the mesh as new limb, the size will be the same 10*10 but if we offset the limb:

offset limb 1,1,10,0,0

The final size will be 20*10 ....so we need something else to apply correctly the texture to the final object.

Cheers.

I'm not a grumpy grandpa
SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 29th Dec 2011 23:11
offset limb?

you should not need to do that.... just: set vertexdata u #1,#2

and it doesnt do the same thing.... it looks completely different with modelprop.

Download model prop and try the 2 mapping functions coded in.

You will see that it is different!

Email me and ill send you a reg key. (no cost)

SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 29th Dec 2011 23:11 Edited at: 30th Dec 2011 22:04
edit:humm double post...lol

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 30th Dec 2011 11:32 Edited at: 30th Dec 2011 12:06
@SMD_3D Interactive

Quote: " Email me and ill send you a reg key. (no cost)"

Thanks.

Take a look to this code and use any image you got, and tell me if the texture looks different from object 1 to object 2.



EDITED
Where can I download your last program with the mapping functions ?

Cheers.



I'm not a grumpy grandpa
SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 30th Dec 2011 20:46
http://www.deved-portal.com/smd3d/modelprop.html

However if you wait till the end of my day today.... I will have the help files updated and new youtube videos posted.

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 30th Dec 2011 20:52
Thanks. I will wait for your new updates.

cheers.

I'm not a grumpy grandpa
SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 30th Dec 2011 22:11 Edited at: 30th Dec 2011 22:18


there ya go.... and no the original code you had...had an error i fixed.

The object on the right is a proper sphere map
and the one i coded with assistance is the one on the left

but like i said is not perfect.

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 30th Dec 2011 22:27
Did my code above looks different in your mashine ? ...I don't see the difference...I will have a look again

Cheers.

I'm not a grumpy grandpa
SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 31st Dec 2011 00:30
I changed your code actualy.... download the code i supplied and try it.

Also Modelprop has been updated!

http://www.deved-portal.com/smd3d/modelprop.html

Also in the new help system it has links to videos i have posted but will require an online connection to view them.

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 31st Dec 2011 00:41
I have tested your last update, and works better...I have tested your last code aswell and you nearly got it working !!

What about the reg key you promised

Cheers.

I'm not a grumpy grandpa
SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 31st Dec 2011 00:46 Edited at: 31st Dec 2011 00:49
send me an email

[email protected]

and i will reply!

If you goto ModelProps thread i also posted some videos....but are accessable with the help system installed with it.

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 31st Dec 2011 00:49 Edited at: 31st Dec 2011 00:50
Ok...do I have to writte smd_3d@ ....or smd3d@ ?? I did send you a mail to [email protected] (just one dot)

Cheers.

I'm not a grumpy grandpa
SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 31st Dec 2011 00:50
needs the underscore.... Also you can add me to msn for better assistance

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 31st Dec 2011 00:55
I have sent right now a mail to you to the mail you gave me

I'm not a grumpy grandpa
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 31st Dec 2011 14:47
Hi there . I have been making test with this great little program and this is my first result animating a single mesh. I'm going to buy it !!

http://www.youtube.com/watch?v=Uv06S0QAFE8&context=C30a4ff3ADOEgsToPDskJOmj8rXgaSij1Yovz5T1bV

Cheers.



I'm not a grumpy grandpa
SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 31st Dec 2011 16:54
your the first to get that done! didnt know mp could do that...lol!

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 31st Dec 2011 17:03 Edited at: 31st Dec 2011 17:03
@SMD_3D Interactive
Hi again. Do you have restriction to saving in this copy ?...It was easy to make the animation, as bones are objects also, but I can't save to .x

Cheers.

I'm not a grumpy grandpa
SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 31st Dec 2011 20:33 Edited at: 31st Dec 2011 20:34
No restrictions..... just doesnt save when it has a solid mesh that is pre rigged...sorry! I will do some investigating to see if i can resolve that. For now create your characters with detachable limbs.

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 1st Jan 2012 07:06
@SMD - I had a look at that spherical texture code, works a treat, a tad stretching on the test texture I used. I played around for a good month or so trying to find a way to do that with no success, just constant pinching on the textures.

If you don't mind me using it I'll convert that to C for my big project and have a tinker with it.

Thanks also to Chafari...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 1st Jan 2012 16:54
Help yourself.... if i find any more tweeking that works i will share!

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 1st Jan 2012 18:07
@WLGfx

Quote: "Thanks also to Chafari"


Well I'm just a user testing the program Happhy new year WLGfx and happy new codes

Cheers.

I'm not a grumpy grandpa

Login to post a reply

Server time is: 2026-07-10 10:20:48
Your offset time is: 2026-07-10 10:20:48