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 / Changing the colour of a multi-coloured .X file

Author
Message
Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 19th Jun 2012 09:16 Edited at: 19th Jun 2012 09:27
Hi everyone,

I've started venturing into .X files, and when parsing a .X file via notepad, I noticed all the colour details in the first part of the file;



When I edit these values, then reload my .X file into my game, I get the expected result. My question is, how could I change these colours live in game without altering the original file, so that whilst the model is showing the colours change or can be changed on the fly?

Perhaps to simplify the problem;



How would I go about adjusting the "Blue" parameter on the fly after this .X file is loaded into my game. I assume that the .X file is loaded into memory, and I can push/pull data to where the colour information is held?

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 20th Jun 2012 02:24 Edited at: 20th Jun 2012 03:31
In thinking about this further, I started reading up on Memblocks, Meshes & Objects.

It seems that when I load my .X file as a mesh, then load that mesh as an object, I find that all the colour data from the original .X file is lost and the object is displayed as a uniform grey.

I would really appreciate any help here...

What I'm trying to achieve is a datamap system, that will taint the colours of the objects that fall under the map. Problem being, my objects consist of around 3-5 colours for various faces.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 20th Jun 2012 03:45
you can't change colors, dbpro doesn't have commands for that.

Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 20th Jun 2012 04:34 Edited at: 20th Jun 2012 05:20
I'm thinking along the lines of, loading the .X data into memory, then changing the blocks that contain the .X Material data, then loading an object from memory.

In other reading, I've found one command which will definitely come in handy;

SET OBJECT DIFFUSE

This has an awesome effect on objects, enabling me to colour objects whilst still keeping their unique material colours.

EDIT: I might just explode my models into multiple .X files. So when ever there's a part of my model that has a unique colour, that will be it's own .X object. Not too sure how many objects are required at this stage. >_>

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 20th Jun 2012 11:24 Edited at: 20th Jun 2012 11:26
If you want to change the colour of individual vertices, you can do that either through memblocks, or by using the vertexdata commands (faster). Note that the original colour of the vertex is lost if you do it this way.

First of all, you need to check that the model you loaded is using the correct frikkin' vertex format (FVF). You can look at that any time by reading the memblock header of it's mesh:



(Just for the record, it's actually "Flexible Vertex Format").

Assuming you ran the above code with your model, you're most likely going to get an FVF of 274 and vertex size of 32 bytes. What does this all mean? Well, here's an extract from the help files:



You'll see that using FVF_XYZ, FVF_NORMAL, FVF_TEX1, so 0x002 + 0x010 + 0x100 = 0x112 = 274. In order to be able to edit the diffuse of each vertex, we need to add the diffuse value to the FVF. So:

MyFVF = FVF_XYZ || FVF_NORMAL || FVF_DIFFUSE || FVF_TEX1

0x002 + 0x010 + 0x040 + 0x100 = 0x152 = 338.

Alright, now in order to be able to do that with the model, we need to convert it's FVF to 338:



Assuming you ran the code, you will now get an FVF of 338 and a vertex size of 36 bytes.

After doing that, you can freely change the diffuse values of every single vertex using the vertexdata commands:



Also, here's a really cool feature that almost no one is aware of. Did you know that you can set individual vertices to be transparent by changing the alpha channel? It requires an additional command for it to work though.



Another thing to note is that the command set object diffuse only works if the object accepts ambient light. Try using set object light 1 , 0 and then set object diffuse, you'll see that nothing will change. This is actually not the case when you edit the individual vertices.

TheComet

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Jun 2012 15:48
Um... COLOR OBJECT and COLOR LIMB appear to be what's wanted here. I don't think it's exactly the same, but it give equivalent effects.

Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 21st Jun 2012 05:30
TheComet, you've been too helpful, I can't thank you enough!

I've spent this morning (whilst in between jobs at work ) reading and understanding your post. So far I've been tinkering with the below;



When testing a simple generated DBpro cube object, the code does what it says on the box, making one side of the cube red. But as soon as I swap out the DBpro box with my "Simple Cube.X" model (attached to this post), the code no longer colours the cube face red. Or if the code is working on my .X model, their is no visible evidence.

IanM, I'm soooo glad you dialed into this thread too! I'm lead to believe that "Color Object" & "Color Limb" colour an entire object, but not a select group of faces/vertices on that object which is what I'm trying to achieve here.

Now that I've got some attention here, I'm not too sure if there's a simpler way of doing what I'm doing here. Considering that the RGB data I'd really love to change on the fly is hosted in just a few lines of code in the .X file. Once I change the Material colour in the .X file, it flows through the entire model as expected, no need to edit vertices independently. Such a shame if I have to parse each every individual vertices just to colour it my desired colour.

To explain what I'm trying to do game play wise; Think of Home World 2, how you could change the stripe colours on your space ships. I'm trying to do this in .X models that don't use textures. Sure, it's probably conventional and a LOT easier to do what I'm trying to do by using textures, but I'm not wanting to learn texturing right now, and rather focus on what is & isn't possible for a simple coloured, but non-textured .X file.

The end result I'm after is an in game eye-dropper, which when adjust, the model colours change before your eyes.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 21st Jun 2012 08:30 Edited at: 21st Jun 2012 08:32
Try making your X model white. I tested The Comet's code, and it works on a white texture. All shades work, but they are added together somehow, and white is the least destructive to the colour choice.

Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 21st Jun 2012 09:30
Using a strictly white model wouldn't be a workable solution, as I paint the models in Wings3D, and in doing this the materials are defined to the vertices then and there.

But I tested making the models white any way, and the same result was had as if they were coloured.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 21st Jun 2012 10:00
Hmm, I'm going to assume it's a limb problem. I found that limb 0 doesn't always give you access to all vertices of the object when you're using external models. Try changing the "0" in the following line with a 1, or a 2, and see what that does.

lock vertexdata for limb 1 , 0 <-- Change that to something else.

Also another problem you may already have noticed is that after conversion of the object's FVF to 338, all of the vertices are coloured black, not white. I suggest doing something along the lines of this in order to access all vertices:



I'm really not sure if that'll fix it though... Let me know if that works.

TheComet

Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 21st Jun 2012 13:40
Thanks again TheComent. Unfortunately I think I've reached my peak in on the fly understanding, and will have to stand back from the techniques being used/discussed here, forfeiting my vertices colour changing wants for the simpler technique of breaking up my models into multiple .X files.

I'm at a stage where I keep getting distracted with the nitty gritty, rather than simply making a damn game! But by all means, I'll continue watching this thread if others continue to comment. Needless to say Bookmarked for a rainy day too.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 21st Jun 2012 15:32
Anyway Set Diffuse is similar.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 21st Jun 2012 18:37
Hmm, well for some reason it doesn't work at all unless you use set object light 1 , 0... And all that does is make the object ugly (but the face is red now!)



I've never understood why that's the case with external models.

You could try removing the object's limbs by converting it to a mesh and back, but you'll lose any textures and lighting:



Is any of this what you're looking for?

TheComet

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 21st Jun 2012 20:02 Edited at: 21st Jun 2012 20:03
I got it to work. I put a Planar UV map on my model, and loaded a white texture, and textured the model in the editor, and turned down the ambient light to about 10, and it looked about right with the colour changes.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 22nd Jun 2012 00:03
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 22nd Jun 2012 01:44
OK...Download....

Login to post a reply

Server time is: 2026-07-08 03:47:53
Your offset time is: 2026-07-08 03:47:53