Delgine 3D Tools & Content DeleD Community Edition
Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

A million and one DMF loading questions...
Goto page 1, 2, 3  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    DeleD Community Edition Forum Index -> DeleD Community Edition
View previous topic :: View next topic  
Author Message
Daaark
DeleD PRO user


Joined: 01 Sep 2004
Posts: 2696
Location: Ottawa, Canada

PostPosted: Wed Mar 02, 2005 1:42 am    Post subject: A million and one DMF loading questions... Reply with quote

Why did you guys change the ambient color to hex in the file format? How do I convert this back to RGB?

Also, were there any changes in the file format since 0.91? My files say 1.00 but the help doesn't cover that version.


Last edited by Daaark on Sat Mar 05, 2005 2:41 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Daaark
DeleD PRO user


Joined: 01 Sep 2004
Posts: 2696
Location: Ottawa, Canada

PostPosted: Wed Mar 02, 2005 7:03 am    Post subject: Reply with quote

Laughing I ask the ambient question because I'm writing a DMF loader in C++. I have no clue how to extract the 3 color floats I need. Confused
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Paul-Jan
Site Admin


Joined: 08 Aug 2004
Posts: 3066
Location: Lage Zwaluwe

PostPosted: Wed Mar 02, 2005 9:11 am    Post subject: Reply with quote

*lol* It is the hex version of the integer-representation of the color.

So step by step:
1. Split the number up in 2-character 'bytes' for A, B, G and R
2. Convert hex to int
3. floatvalue = value / 255;

Or
1. Convert hex to int
2. R = number and $000000FF, G = number and $0000FF00, B = number and $00FF0000
3. floatvalue = value / 255

The reason why is because it is a standard encoding, and we use it for the texturelayer-color as well. We wanted to encode both colors the same way, so we had to make a choise. Converting an integer-color to floats seemed more contra-intuitive than the other way around, as the extra precision you get from a float as spurious anyway.
Back to top
View user's profile Send private message Visit poster's website
Daaark
DeleD PRO user


Joined: 01 Sep 2004
Posts: 2696
Location: Ottawa, Canada

PostPosted: Wed Mar 02, 2005 4:44 pm    Post subject: Reply with quote

Don't you mean / 256 ? Confused
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Paul-Jan
Site Admin


Joined: 08 Aug 2004
Posts: 3066
Location: Lage Zwaluwe

PostPosted: Wed Mar 02, 2005 6:23 pm    Post subject: Reply with quote

Nope, to map an integer range [0-255] to the float range [0-1] (mind the square brackets: range inclusive), you have to divide by 255.

Otherwise you'll never get those bright-and-shiny colors you know Wink
Back to top
View user's profile Send private message Visit poster's website
Daaark
DeleD PRO user


Joined: 01 Sep 2004
Posts: 2696
Location: Ottawa, Canada

PostPosted: Wed Mar 02, 2005 6:30 pm    Post subject: Reply with quote

To convert hex to int I you do what exactly? Embarassed (I never touch hex.. I ignore it's existance)...

Also, why is alpha included? Why would someone use an alpha value for an ambient color? Makes no sense... I guess you just leave it there for future use (Whatever that might be...) Or failing that, so it loads into a 32bit colour.
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Paul-Jan
Site Admin


Joined: 08 Aug 2004
Posts: 3066
Location: Lage Zwaluwe

PostPosted: Wed Mar 02, 2005 6:46 pm    Post subject: Reply with quote

Heck, even my basic is better than my C, but I am guessing a sscanf would do the job, wouldn't it? There probably is a better way, but I wouldn't know Very Happy

About the alpha-value, you guessed right, no we don't use it at all, and it's not likely we ever will, but we just store colors as 32bits number by default.
Back to top
View user's profile Send private message Visit poster's website
Daaark
DeleD PRO user


Joined: 01 Sep 2004
Posts: 2696
Location: Ottawa, Canada

PostPosted: Wed Mar 02, 2005 6:52 pm    Post subject: Reply with quote

It will always be 8 chatacters, 2 for each component? Smile

I'm doing this... I know atof is wrong.. I'm trying to google for how to convert the hex string to an int... no luck so far.

Code:

    //grab the ambient color
    //and convert the hex value back
    //to 3 floats
    fMap.get(ca,2); //alpha
    fMap.get(ca,2); //r
    m_LightAmbient[0] = float(atof(ca)) /255;
    fMap.get(ca,2); //g
    m_LightAmbient[1] = float(atof(ca)) /255;
    fMap.get(ca,2); //b
    m_LightAmbient[2] = float(atof(ca)) /255;
    fMap.get(ca,256,';');
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Daaark
DeleD PRO user


Joined: 01 Sep 2004
Posts: 2696
Location: Ottawa, Canada

PostPosted: Wed Mar 02, 2005 8:38 pm    Post subject: Reply with quote

I have a material that I clicked on in the sidebar, and was never actually applied to any object tat was saved out with my map. Confused I misclicked on the [<] button, and ended up in nature, with the water texture selected. Embarassed It's not part of any object on the map.

Shouldn't that be removed on save?
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Daaark
DeleD PRO user


Joined: 01 Sep 2004
Posts: 2696
Location: Ottawa, Canada

PostPosted: Thu Mar 03, 2005 8:50 pm    Post subject: Reply with quote

I just made a test dmf to use with my loader. I made one cube, and saved, and all these materials were saved out with it.

Code:
DeleD Map File;
Version 1.0;
no-name-yet;00FFFFFF;75;
16;
0;system;System;0;1;0,System\system.bmp,1;
1;Floor02;Floors;0;1;0,Floors\Floor02.jpg,1;
2;Floor04;Floors;0;1;0,Floors\Floor04.jpg,1;
3;Floor10;Floors;0;1;0,Floors\Floor10.jpg,1;
4;Floor11;Floors;0;1;0,Floors\Floor11.jpg,1;
5;Water01;Nature;0;1;0,Nature\Water01.jpg,1;
6;Roof03;Roofs;0;1;0,Roofs\Roof03.jpg,1;
7;Roof04;Roofs;0;1;0,Roofs\Roof04.jpg,1;
8;Wall01;Walls;0;1;0,Walls\Wall01.jpg,1;
9;Wall02;Walls;0;1;0,Walls\Wall02.jpg,1;
10;Wall06;Walls;0;1;0,Walls\Wall06.jpg,1;
11;Wall10;Walls;0;1;0,Walls\Wall10.jpg,1;
12;Wall11;Walls;0;1;0,Walls\Wall11.jpg,1;
13;Wall12;Walls;0;1;0,Walls\Wall12.jpg,1;
14;Wood01;Wood;0;1;0,Wood\Wood01.jpg,1;
15;Wood02;Wood;0;1;0,Wood\Wood02.jpg,1;
1;
cube1;1;1;-1;1;-1;-1;User info;
14;
32;-32;32;
-32;-32;32;
-32;-32;-32;
32;-32;-32;
32;32;32;
-32;32;32;
-32;32;-32;
32;32;-32;
0;0;32;
-32;0;0;
0;0;-32;
32;0;0;
0;-32;0;
0;32;0;
24;
3;0;8;0;1;0.0000;0.0000;0.2500;-0.2500;-0.2500;-0.2500;
3;0;8;1;5;0.0000;0.0000;-0.2500;-0.2500;-0.2500;0.2500;
3;0;8;5;4;0.0000;0.0000;-0.2500;0.2500;0.2500;0.2500;
3;0;8;4;0;0.0000;0.0000;0.2500;0.2500;0.2500;-0.2500;
3;0;9;1;2;0.0000;0.0000;0.2500;-0.2500;-0.2500;-0.2500;
3;0;9;2;6;0.0000;0.0000;-0.2500;-0.2500;-0.2500;0.2500;
3;0;9;6;5;0.0000;0.0000;-0.2500;0.2500;0.2500;0.2500;
3;0;9;5;1;0.0000;0.0000;0.2500;0.2500;0.2500;-0.2500;
3;0;10;2;3;0.0000;0.0000;-0.2500;-0.2500;0.2500;-0.2500;
3;0;10;3;7;0.0000;0.0000;0.2500;-0.2500;0.2500;0.2500;
3;0;10;7;6;0.0000;0.0000;0.2500;0.2500;-0.2500;0.2500;
3;0;10;6;2;0.0000;0.0000;-0.2500;0.2500;-0.2500;-0.2500;
3;0;11;3;0;0.0000;0.0000;-0.2500;-0.2500;0.2500;-0.2500;
3;0;11;0;4;0.0000;0.0000;0.2500;-0.2500;0.2500;0.2500;
3;0;11;4;7;0.0000;0.0000;0.2500;0.2500;-0.2500;0.2500;
3;0;11;7;3;0.0000;0.0000;-0.2500;0.2500;-0.2500;-0.2500;
3;0;12;3;2;0.0000;0.0000;0.2500;-0.2500;-0.2500;-0.2500;
3;0;12;2;1;0.0000;0.0000;-0.2500;-0.2500;-0.2500;0.2500;
3;0;12;1;0;0.0000;0.0000;-0.2500;0.2500;0.2500;0.2500;
3;0;12;0;3;0.0000;0.0000;0.2500;0.2500;0.2500;-0.2500;
3;0;13;4;5;0.0000;0.0000;0.2500;0.2500;-0.2500;0.2500;
3;0;13;5;6;0.0000;0.0000;-0.2500;0.2500;-0.2500;-0.2500;
3;0;13;6;7;0.0000;0.0000;-0.2500;-0.2500;0.2500;-0.2500;
3;0;13;7;4;0.0000;0.0000;0.2500;-0.2500;0.2500;0.2500;
0;


I never even touched the material editor thing, or the sidebar. I just drew a cube and saved.
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Jeroen
Site Admin


Joined: 07 Aug 2004
Posts: 5332
Location: The Netherlands

PostPosted: Thu Mar 03, 2005 8:57 pm    Post subject: Reply with quote

That is correct behaviour. DeleD loads a default material list (.DML) when starting a new scene. This is convinient because you then have a set of materials you can work with right away. When saving your new map, these materials are all copied to the DMF so the DMF is a totally selfsupporting fileformat (the scene doesn't require the standard DML).
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Daaark
DeleD PRO user


Joined: 01 Sep 2004
Posts: 2696
Location: Ottawa, Canada

PostPosted: Sat Mar 05, 2005 2:06 am    Post subject: Reply with quote

strtoul is the way to go! Laughing

okay, finally found out what to do... between this, and headache of using fstream I'm fed up already. Smile
Code:
//grab the ambient color and convert the hex
//value back to 3 floats
fMap.get(ca,3); //alpha -- unused
fMap.get(ca,3); //red
m_LightAmbient[0] = ((float)strtoul(ca,NULL,16)/255);
fMap.get(ca,3); //green
m_LightAmbient[1] = ((float)strtoul(ca,NULL,16)/255);
fMap.get(ca,3); //blue
m_LightAmbient[2] = ((float)strtoul(ca,NULL,16)/255);
fMap.get(ca,256,';');
fMap.get(c);
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Daaark
DeleD PRO user


Joined: 01 Sep 2004
Posts: 2696
Location: Ottawa, Canada

PostPosted: Sat Mar 05, 2005 2:39 am    Post subject: Reply with quote

Embarassed Why is it that you switch from a semi-colon to a coma half way through the material listings?
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Paul-Jan
Site Admin


Joined: 08 Aug 2004
Posts: 3066
Location: Lage Zwaluwe

PostPosted: Sat Mar 05, 2005 8:26 am    Post subject: Reply with quote

Semi-colon seperates items, coma (comma?) separates sub-items.

So the layers are separated by a semi-colon, the individual characteristics of a single layer a separated by coma's. It's a new concept Jeroen introduced with the materials, and I think he is right: it _does_ make things easier to read. For a human that is (which is the whole point of having a text-based file format). My parsing algorithm couldn't care less Smile
Back to top
View user's profile Send private message Visit poster's website
Daaark
DeleD PRO user


Joined: 01 Sep 2004
Posts: 2696
Location: Ottawa, Canada

PostPosted: Sat Mar 05, 2005 8:47 am    Post subject: Reply with quote

I wish I would have realized that before I coded the whole thing using ';'s lol. *back to square one* took me a good long time to see that it was comas there lol. Also that and the '\' characters becoming escape sequences when I was printing out stuff for debug purposes. Confused


Laughing

My parsing code is the stuff of nightmares. There has to be an easier way!
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    DeleD Community Edition Forum Index -> DeleD Community Edition All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
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