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 / How to texture a single surface of many in a mesh? (amoung other things...)

Author
Message
Jesse_Angell
16
Years of Service
User Offline
Joined: 9th May 2010
Location:
Posted: 10th May 2010 01:45 Edited at: 10th May 2010 20:12
Hello!

As you can see I am new, just as I am new to DBPro. I am attempting to create a dynamic console screen on a 3D mesh. The idea is the console does not have a simple animated or static texture, but actually has a texture that updates according to player interaction. In other words I would like to have some buttons on it, as well as it changing when needed.

So far I have been able to create a bitmap, draw to it, and then copy it to an image, and texture a cube with it. My code is very inefficient but it works for the moment. I would now like to be able to bring in my .x mesh of my console and texture the screen surface of it.

Afterwards I will change the random text that is currently being drawn to the bitmap buffer, into something more elaborate like rectangular buttons. I would like to be able to know when I click on the surface whether or not I am clicking inside the pixel range of the buttons. Or would it be the U V range? I will need a indepth explanation of how this works and how to accomplish it.

So, here is what I have so far. Any suggestions of optimization or criticism is welcomed.


Thank you for your time. I hope to hear from you soon.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th May 2010 15:27
Well you can't do what you want with the standard DBPro cube - it uses the same texture coordinates for each face, and in addition, DBPro doesn't allow you to texture per face - it allows you to texture on a per limb basis.

There are 3 ways to proceed:
1. Create a cube in a modelling package that will provide you with 6 different limbs, each containing a face of the cube - this is the easiest.
2. Adjust the texture coordinates of the faces on the cube to allow each face to use a different portion of the texture you assign.
3. Create a new cube using code to provide 6 different limbs.

Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 10th May 2010 16:04
Every time I've considered this, I come to the conclusion that a single plain is the best option, a plain as a separate object that can easily be hidden and ignored when not in view, and can be orientated and neatly consider that in the 3D world to 2D fake screen calculations.

With a display object, like a model of a TFT monitor for instance, you would position and rotate, and scale your plain to sit inside, as if the plain is the actual screen itself. You could even have it sit inside the model, if you then make good use of alpha transparent textures, you can do some cool effects. For instance, have a bloody hand print on the screen, have a crack in the screen, or just some dust. You would need a way to meticulously position and rotate these plains, but it's not rocket surgery really.

It's use pick object to guage the 3D location that was clicked, then with the screens position, rotation and size, work out where in 2D on the actual screen that would be. Tricky math, but I don't think there's an easier way. You could just have a plain positioned where the pick object hits and rotated the same as the screen - silky smooth 3D/2D cursor just like in Doom3. I would consider working out the corner positions of your screen and try using a distance formula. If you know where the sides of your screen are in 3D, and you know the clicked position in 3D, then you should be able to convert that by working out the distance between the sides (length of screen), and the distance from the left side to the clicked position, work out a percentage then convert that to an actual 2D image position.

One option would be to have your TFT monitor model, and a plain object to go with it, lined up with the monitor already. One benefit of this is that you can put little cubes in each corner, as separate limbs, then these can be very very useful in working out and converting positions from 3D clicks to 2D texture locations.

If you cant work out the 'live' mouse pointer stuff - you could just have it so the mouse pointer appears when you click on the screen, then have it move on the texture in relation to the real mouse - while the camera stays where it is.


For actually drawing the huds for the screens and updating them, I'd consider ImageKit, which lets you draw to images directly - you could program a GUI for it if you wanted, hell you could write another game inside your game and have it play on the VDU. It could even use a camera, render an extra camera to an image, texture that onto the plain, and position and rotate the extra camera to suit a security camera - panning left and right, watching live action .


Health, Ammo, and bacon and eggs!
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 10th May 2010 17:55 Edited at: 10th May 2010 17:55
You could use the dbflasher plugin to render a flash applet to a particular face, (read limb) therefore giving the effect you're after.

My signature is NOT a moderator plaything! Stop changing it!
Jesse_Angell
16
Years of Service
User Offline
Joined: 9th May 2010
Location:
Posted: 10th May 2010 19:54
Very interesting suggestions. I guess, what I could do, is just simply create 2 .x files, one for the screen, one for the base and texture one and the other accordingly.

As for clicking on the screen, is there a way to retrieve what texel one is clicking on?
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 11th May 2010 00:44
If you add 4 extra limbs, one in each corner of the screen, then you could just work out the distance from the side, and top, and work out the texture location from that.

I might have time to make a little example, will see what I can do.


Health, Ammo, and bacon and eggs!
Jesse_Angell
16
Years of Service
User Offline
Joined: 9th May 2010
Location:
Posted: 11th May 2010 01:05
Hmm... I'm not really sure how I could accomplish that or how exactly am I supposed to do that.

If you could provide a small example and a detailed explanation it would be much appreciated.

I imagine I will have to make an editor to do this later on. Well then, thank you.
Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 11th May 2010 20:18 Edited at: 11th May 2010 20:21
That's a good idea, VanB. Hadn't thought of that.

If DBPro can't texture per face, can anyone explain how DBPro's okay with loading this file? I've attached it.

The .zip contains three files:
- cube.x - the model
- side1.jpg - texture 1
- side2.jpg - texture 2

The cube uses three different materials all for the same limb. Two of the materials use different textures, and one doesn't at all.

I have no idea how DBPro deals with this internally and I don't know if there's a way to achieve the same behavior through code, but any light someone can shed on the subject would be very much appreciated.

Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 13th May 2010 03:42 Edited at: 13th May 2010 03:58
@ Kira
I have been able to get 128 textures on one mesh. I do it ALL the time. It is easiest to do in Ultimate Unwrap or Milkshape. Not so easy in DBPro,(and I mean doing the texturing within DBpro. Externally created models, like your example, are fine. In fact, your model is quad based, and remember everyone said DBPro can't read quads? Oh, yes it can!) unless you write a custom .x file exporter,or, use limbs.
In UU, for example, you just select faces in the 3d window, then assign a texture to them. Just add more textures to the list, and you can assign them to individual triangles, if you wanted to.
Grouping the faces makes it easier to keep track of them.
Its why I like UU so much, its like fine tuning the model

I commented and included the relevant bits in your cube mesh.



here is a good reference for the DirectX file format:

http://local.wasp.uwa.edu.au/~pbourke/dataformats/directx/#xfilefrm_Template_MeshMaterialList
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 13th May 2010 04:12
Well you could if you didn't want to do all that math is position a cube over each button on the ingame consol screen and use Object Screen X and Y to find where it is on the screen. Then check if your mouse is near that position and if so make it choose the coorsponding button by pasting whatever screen you want onto the consol texture.

If it hasn't exploded yet, I haven't touched it.
Brendy boy
21
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 13th May 2010 05:32
Quote: "If DBPro can't texture per face, can anyone explain how DBPro's okay with loading this file? I've attached it."

DBPro's object's internal structure has an array of material data which tells dbpro which face has which material. That array gets filled when you import an object in x format. However there is't a command in dbpro that allows you to change the particular values in that array. There's only texture limb command that when used erases that array and tels dbpro that limb has only one texture/material.

God is real unless declared integer.
Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 13th May 2010 08:08 Edited at: 13th May 2010 08:10
@Visigoth: I am well aware of the insides of a .x file. Check the sig. I was looking for a way to do the same from inside DBPro.

Edit: Ironically, I wrote the script that wrote that file.

@Brendy boy: I was afraid that was the case

Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 13th May 2010 08:13 Edited at: 13th May 2010 08:31
@kira
Well, if you can write a script to write an .x file, what's your trouble?
Like I said, it can be done within DBPro, you just need a custom .x file exporter.
A built in function in DBpro to assign textures to faces, doesn't exist, you should know that.

edit:
and the reason why DBPro read your cube file is because it is a valid DirectX file that DX9 can process. This is no secret, is all I was trying to say.
I suppose, if you wanted to, you could write a custom .x file exporter to add in the material list and the faces the materials mapped to. But then we'd be talking about a modeling program, like Blender, wouldn't we?
Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 13th May 2010 08:28
I think it's irritating that we can't change the material a face uses from inside DBPro, we can only load in objects that have it all setup at the beginning. I was just hoping someone knew a way of editing the object's materials.

Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 13th May 2010 08:36 Edited at: 13th May 2010 08:41
well, if you wanted to try something, try changing the filenames of the textures. Maybe use the copy file() command

edit:
I don't think it would be too fast, but, could you copy a file to an existing file? You'd have to delete the original first. Might be a good test?

edit:
or, better yet, just modify the .x file to change the material filename. That should be pretty fast.
Kira Vakaan
17
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 13th May 2010 09:59
From DBPro? If I changed the .x file, I'd have to reload it. That's probably not acceptable in most circumstances. Ah well. I'll just use a separate limb if I need something like this.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th May 2010 13:12
I'm sure it would be an easy matter for Lee to change the texture object and texture limb commands so they include an extra parameter for the materials. Might even be possible for individual faces too as long as there's a simple way of identifying which face you want - which I doubt.

We could pester IanM to include something like this in his Matrix1 utilities.
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 13th May 2010 14:19
Quote: "We could pester IanM to include something like this in his Matrix1 utilities."

Hum yeah, that is a good idea, GG. And adding an extra parameter for the texture stages, so we could apply shader FX on individual faces.

No offense, IanM.

Cheers

Slayer rules!!! Yeaaah, man!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th May 2010 14:46
Quote: "No offense, IanM."


I can't see how he can be offended when we think he's the man for the job.

But there's no telling with Mods sometimes.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th May 2010 23:07
Well, TBH, I should be working on fixing bugs right now, so I'll add it to my list to investigate sometime soon.

paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 15th May 2010 14:26
Slightly off topic but i've been working on a sort of uv mapping tool in DBPro,early stage yet but if any body wants it i'll post up the basic code to have a play with.

Login to post a reply

Server time is: 2026-07-25 23:12:16
Your offset time is: 2026-07-25 23:12:16