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 / Texturing a combined object

Author
Message
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 3rd Mar 2018 00:21
After figuring out how to create my giant object.

I move on looking for a simple way to texture it.

Currently, I parse the X-file and insert the texture data, to view these changes I must save x file manually/ load object.

Faces are stored in the giant mesh file at the time of creation of the massive object. 2 faces per wall or floor at the time they were added. This is good to know as now I can index into the giant object faces now quite easily.

Which leads to the Visual Editor...DUN DUN DUN!
In my test level, ie the giant object, which is really only a 5x5 map at the moment to make testing easier, I am looking at several ideas for multi-face selection.

My first idea, which I will try and implement today, involves selecting a face (or multiple faces) and changing the face colors. Then apply the texture to those colored faces with the save/load thing. I might need a duplicate object for this...not sure yet. I could also use my copy of the combined object before it's combined, I believe that would make selecting easier since they are all separate objects. Maybe I can ghost 1 object over the other or even wire-frame it over the other.

As I said I have several other ideas in my notes, and thought this one would be the easiest to implement...We shall see.

The drawback to doing this is, of course, all the saving and loading when I want to view the texture changes. So, I'm trying to minimize that with multi-face selection.

ONWARD!
Green Gandalf
13
Years of Service
User Offline
Joined: 3rd Jan 2005
Location: Cornwall UK
Posted: 3rd Mar 2018 00:45
Sounds good.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 3rd Mar 2018 02:12
I was overthinking things.

The solution was simple.

Use the un-combined object as the guide. I hide this offscreen. I also hide the combined object.

Make a mesh of the Combined Object.


Select an object in the uncombined object (I currently use the arrow keys to move through the uncombined object sequentially.) Spacebar to tag it so I can do more than 1.

Since I know how the combined object is created from the uncombined object. I index to the proper pair of faces.

Change the vertex colors of the selected faces in the temp Mesh I create.

Apply texture to the selected faces in the combined object.

View Level, do the save load thing to see the changes on the combined object.

Maybe not the best way, but it works.

TODO:

After the save-reload...
In the mesh, when the face has a texture, color-code them so I know which faces I already applied a texture to. red: texture1, green: texture 2, blue texture 3...etc...or something similar.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 3rd Mar 2018 07:35
Well, this is working pretty good as is.

If I could find a way to refresh an object with out actually saving and loading, it would be so much sweeter. Perhaps some kind of direct memory access to the object itself....Hmmm.

While I ponder that, some tweaking and optimizing of the current code is in order now.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 3rd Mar 2018 10:17
I thought you get get a PTR to an object, but that doesn't seem to exist. (maybe it was a DLL)

You can get a pointer to memblock created to a mesh, but the mesh destroys all the texture data.

Still researching...


Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 3rd Mar 2018 21:45
Ok.

I have successfully managed to damage an object using direct memory access. I haven't experimented farther than that.

So, it should/might be possible, in theory, to change it's textures 'on the fly'

Just need to spend some time finding the right memory offset(s) into the texture info.
Green Gandalf
13
Years of Service
User Offline
Joined: 3rd Jan 2005
Location: Cornwall UK
Posted: 3rd Mar 2018 22:46
That'll be the fun part. Hope you get it sorted out and let us know the outcome. Have you looked at the Matrix1 Utilities Plugin? It might help with this.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 3rd Mar 2018 23:31
Quote: "That'll be the fun part. Hope you get it sorted out and let us know the outcome. Have you looked at the Matrix1 Utilities Plugin? It might help with this.
"


Had a quick look through all the commands. Didn't find anything that looked like it would be useful.

Get PTR To Object(), would be useful. But it's not there.

hunting through memory now, trying to locate texture names...
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 3rd Mar 2018 23:55
To make things easier, I only have 1 texture on the object.

t4.png

Now searching through memory, I find several instances of that name

and 1 instance of

t4.dds (interesting, since I don't use or reference that name in the program, the model, or in the project folder)

Looks like it is converted internally to dds to send to D3D.

This may be what I'm looking for....

More testing is needed.
Green Gandalf
13
Years of Service
User Offline
Joined: 3rd Jan 2005
Location: Cornwall UK
Posted: 4th Mar 2018 00:20
Quote: "Get PTR To Object(), would be useful. But it's not there."


Yes, I thought that too. Would it be possible to use something like the snippet below?



Admittedly a make bank from object command would be nice too.

You can access the individual elements of the memory bank copy of the object and modify them I suppose. I've not tried doing this sort of thing myself but it should bypass the restrictions imposed by the built-in memblock and mesh commands.
revenant chaos
Valued Member
11
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 4th Mar 2018 00:45 Edited at: 4th Mar 2018 00:46
Hi Zep,
You can obtain a pointer to a limb's/mesh's internal sMesh structure by locking it's vertexdata and calling Get Vertexdata Ptr()

Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 4th Mar 2018 02:45
Quote: "Yes, I thought that too. Would it be possible to use something like the snippet below?"


I'll look into that.

Quote: "You can obtain a pointer to a limb's/mesh's internal sMesh structure by locking it's vertexdata and calling Get Vertexdata Ptr()"


Don't know if that contains the info I'm looking for, The Objects Texture Data,

I'll mess around with it later as well.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 4th Mar 2018 04:14
GG Said: wrote: "Yes, I thought that too. Would it be possible to use something like the snippet below?"


Hey GG, I played around with this a little...looks promising. Doing some tests now.

Thanks for the snippit.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 4th Mar 2018 05:21 Edited at: 4th Mar 2018 05:24
BEWM!

Time: is the time it takes to re-texture a face on the fly.

This is my 100x100 map, so I expect that time to go down.

Attachments

Login to view attachments
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 4th Mar 2018 05:27
Beer Time!
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 4th Mar 2018 07:03 Edited at: 4th Mar 2018 07:05
So do to this, I need 5 objects/meshes, the direct memory access info, and the bank stuff from M1U.

I'm beer-ing now, but as I think...I think I can optimize it further.

As for the screenshot: "time":
You can see in the lower left the face I changed. 1/2 face "rock" 1/2 face "beige"

Right now I am doing 1 Face at a time, haven't added the multiple face tagging into my test yet.

When I add that in, the "time" should go down even further or at least do multiple faces in the same "time"

I'm not really concerned (to much) about the "time", as this is for the map compiler, not my project.

The wire frame of the faces looks better with ghost object on on the textured object (not in the screenshot), but then, the actual textured object is quite faded and hard to see.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 4th Mar 2018 07:32 Edited at: 4th Mar 2018 07:39
On that note, the word doc DBO FORMAT SPECS in my "help/documents" folder are dated 8th December 2003

Is there a newer version? Because the info doesn't match up to what I'm seeing in the DBO format of 1.0761 or the 1.077 when I read it and try to parse a DBO.
Mage
11
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 4th Mar 2018 07:36
That's going to upset me in about a week when I start reading the document and try to write code to read DBO files.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 4th Mar 2018 07:43
Quote: "That's going to upset me in about a week when I start reading the document and try to write code to read DBO files.
"



Agreed!

I honestly don't need it, but I think I could optimize even more if I had the latest and greatest version of that document/specs.
revenant chaos
Valued Member
11
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 4th Mar 2018 09:29 Edited at: 4th Mar 2018 09:31
I'm not quite sure what you mean by "the object's texture data", If you mean data that describes which textures are applied to the device when rendering, then no. If you are referring to per-vertex uv coordinates, then yes they can be manipulated through that pointer. That pointer leads to the memory which is manipulated by the vertexdata commands. It is also the memory which is referenced used when constructing memblocks, meshes, and banks from an object or it's limbs.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 4th Mar 2018 09:52
Quote: "I'm not quite sure what you mean by "the object's texture data", If you mean data that describes which textures are applied"


Yes, that texture data is what I need (...or needed, but no longer...)
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 4th Mar 2018 10:23
Quote: "Yes, that texture data is what I need (...or needed, but no longer...)"


Now, I could have probably done it without that texture information. But it makes reading, writing and saving the texture information so much easier.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 4th Mar 2018 10:39
I'm trying to update the DBO doc as I go to what I think it needs instead of what it says.

I believe it would make things much faster for my face texturing thing than what I have now.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 4th Mar 2018 11:29 Edited at: 4th Mar 2018 11:55
Hoo boy...

Somewhere along the chain of texturing a face it eats up 10MB per face. Not good. (I should have checked mem usage sooner, My bad)

I suspect it's the M1U Utils.

I could live with a little loss, but 10MB per face is not acceptable.

I didn't lose any memory at all my old way.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 4th Mar 2018 11:40
I will try deleting the BANK and recreating it when I want to change a texture face.

But every time I do that, I would have to reload the Object(s). I didn't have to do that the old way.

Deleting a bank and recreating it is another 1/2 a second.
Green Gandalf
13
Years of Service
User Offline
Joined: 3rd Jan 2005
Location: Cornwall UK
Posted: 4th Mar 2018 11:59
Sounds like progress up to a point. I hope you are going to share the code when you've got it finished - or even before then?

The naive way I would do this is to manually (via code of course) create the material info per face and save it as an X file. Am I right in thinking that you've tried that? I can see it could be slow.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 4th Mar 2018 12:11 Edited at: 4th Mar 2018 12:24
Quote: "The naive way I would do this is to manually (via code of course) create the material info per face and save it as an X file. Am I right in thinking that you've tried that? I can see it could be slow.
"



Yes, you are on the right track as far as the process is concerned.

When I want to actually view the object after changing face texture(s). I must reload all 5 objects/meshes.

That's why the "multi-texture" selecting/tagging thing is so important. So I only have to reload when i want to.

I don't "create the material" per face, though. I may have to add a material if it doesn't exist in the object. Which is easy.
Green Gandalf
13
Years of Service
User Offline
Joined: 3rd Jan 2005
Location: Cornwall UK
Posted: 4th Mar 2018 14:37
Quote: "I don't "create the material" per face, though."


No I know. That was careless wording on my part . What I meant was the material id per face - and, as you say, if it doesn't already exist just add a new one.

I'm not sure but I suspect you can't extend this approach to additional texture stages - which you'd need if you wanted to use normal mapping with different normal maps per face. That's one reason why people often use a texture atlas in this situation (although I guess you might have problems getting a suitable set of UV coordinates ).

It'll be interesting to see what you eventually decide to do.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 5th Mar 2018 00:05
Quote: "I'm not sure but I suspect you can't extend this approach to additional texture stages - which you'd need if you wanted to use normal mapping with different normal maps per face."


Can you explain this a little or give me an small example of what you are talking about? I don't understand your meaning.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 8th Mar 2018 04:50
Damn..I'm getting old

So, after finally figuring out the data I need from the DBO, I load up my old massive object project.

WTF...I thought this massive combined object was only ONE draw call...now it's showing FOUR!

Panic ensues that I messed something up without knowing what I did.

Spend about an hour searching the code...maybe I added some test objects or something I forgot to delete...nope...meshes, images...? Nope.

So, I just test selecting some faces and re-texturing them while I think, at least this part still works..... When suddenly! It hits me!

I forgot each extra texture used in the massive object adds +1 to draw call.

Crisis averted!

DOH! I IZ DUM!
Green Gandalf
13
Years of Service
User Offline
Joined: 3rd Jan 2005
Location: Cornwall UK
Posted: 8th Mar 2018 15:02
The bad news is that it gets worse over time. The good news is that you are not alone.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 9th Mar 2018 06:03
Hoo boy...

I managed to retexture a 4x4 DBO map with existing textures in the DBO.

Now work begins on what I think will be the harder part.
Adding a texture to the DBO, and reindexing the data so some faces to point to the new texture.
It appears doable with my 4x4....100x100 may be a different story.

If I can get this working well, I can reduce my object count down to 2 (the wireframe and the actual object), and toss out the direct memory access stuff.

Right now I just select a pair of faces using the arrow keys. Forward or backward thru the face list. That works fine on a 4x4. It's going to be inefficient on a 100x100.
Going to see if I can come up with some way to access the face pair data the mouse pointer is on.
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 9th Mar 2018 10:13 Edited at: 9th Mar 2018 10:19
Quote: "Going to see if I can come up with some way to access the face pair data the mouse pointer is on."


So, this doesn't seem possible without a plugin...which I don't even know if such a plugin exists.

I've come up with another idea.

As I build my combine object with "add mesh", I build a another object at the same time with limbs (either add limb or glue limb)

Now, with that idea, I also add a massive amount of draw calls (at 100x100). But this is the "map texture-er", so FPS is not really an issue, within reason.

But with this idea, I can use a "pick object" command, and from the object picked and index into the Face Data of the combined object/wireframe object.

Man, I'd like sometimes to get back to making the actual game instead of the Editor...But so far, these problems I run into, I find very interesting.

But, back up to 3 objects to do this. :sadface:
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 9th Mar 2018 10:30
Quote: "But, back up to 3 objects to do this. :sadface:"


Oh...Hmmm, maybe I can get rid of the "wireframe" of the combined object and wireframe all the lmbs of the limb object.

Also it has hit me, that I don't really need the wireframe object to have textures, so that also reduces draw calls. Currently I display the combined object twice (1 in wireframe mode, one texture mode)

Then it's down to 2 objects loaded (1 with many draw calls, but 1/2 of those currently, because no textures).
Zep
15
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 9th Mar 2018 14:09
Productive day of coding.

So I think this is possible now with the 2 objects, (The giant combined textured object and the untextured giant limb object)

With several arrays, I can figure out the face data and place a ghost plane (or just ghost the limb) where you want to texture the main object.

Still some bugs to work out, but I think it's going to be doable and at an OK to Good frame rate even for a 100x100 map.

Login to post a reply

Server time is: 2018-06-24 08:09:26
Your offset time is: 2018-06-24 08:09:26