Page 1 of 1

Importing multiple textures in a single model

Posted: 10 Feb 2012, 19:39
by Shanker
I am currently modelling a unit for a Spring game which consists of many different parts (head, feet, hands, torso) is there a way to import a seperate texture file for each of these pieces of the model

Re: Importing multiple textures in a single model

Posted: 10 Feb 2012, 19:46
by Beherith
There isnt. But there is a workaround:
You can linearly transform the UV coords of each piece, then merge the texture in photoshop.

Re: Importing multiple textures in a single model

Posted: 10 Feb 2012, 20:01
by smoth
Or just map all the parts to one uv map:
smoth wrote: Model
Image
map
Image

Re: Importing multiple textures in a single model

Posted: 10 Feb 2012, 20:50
by KaiserJ
hey now, i believe hold the crown for "most autistic use of texture atlases"

but yes, it'll be a matter of combining all of your unit textures into an atlas, and then adjusting and combining your uvw coordinates (it sounds painful but it's really not so bad)

Re: Importing multiple textures in a single model

Posted: 10 Feb 2012, 23:54
by CarRepairer
As a non-modeler who gets art from the web, I had to learn this process out of necessity. It consumes 80% of my modding time. :|

Re: Importing multiple textures in a single model

Posted: 11 Feb 2012, 00:04
by smoth
KaiserJ wrote:hey now, i believe hold the crown for "most autistic use of texture atlases"
wasn't trying to claim to that, just showing an example

Re: Importing multiple textures in a single model

Posted: 12 Feb 2012, 01:05
by Shanker
Thanks for the help guys

Re: Importing multiple textures in a single model

Posted: 13 Feb 2012, 05:37
by SpliFF
This is on my TODO list for ASSIMP models. The importer is perfectly capable of reading multiple textures for models however spring itself does not support storing or rendering them. What needs to happen is textures being handled on a per-piece basis rather than per-model.

That means engine changes including some significant rendering queue changes, because currently spring renders unit display lists in order of the texture names (it does this because it's faster to render all objects using the same texture in one go).

If none of that made sense then the simple explanation is that multiple texture support is possible, but not easy - and someone (me) needs to find the time to do it.

Re: Importing multiple textures in a single model

Posted: 23 Feb 2012, 15:11
by MR.D
Isn't it just the format limitation in spring?

I used to make models for Halflife back in the day, and even back then it had support for multi-texture maps for a single object.

An example being say.. a gun.
You assigned sub-groups of polygons afaik, just breaking down parts of the model so each seperate object was assigned its own uv map.

Say on a rifle, I would make 1 uvmap for the Reciever, 1 map for the magazine and bullets, and if need be 1 for a scope or other parts, and it worked fine like that.

Then a script file was generated listing each object and its corresponding UV map.

Everything was then compiled into a single .mdl model, and the script kept track of the sub-objects and uv maps.

Its not so different from how spring models are, at least what I remember.

When I made models for spring, there were many different sub-groups all collected together to make a single model, just that it all shared 1 UV map for convenience.

What made it frustrating for me in spring, is that after you had built your model and Uv-mapped it, you'd have to detach each seperate moving part, re-center origins, and a bunch of other annoying stuff.

Having multiple textures for each model, could be a time saver.

Then you could just build your model piece at a time quickly, instead of having to tear it all down again for the final compile.

If its efficient in the end, as far as memory consumption/render ect, I have no clue.

Re: Importing multiple textures in a single model

Posted: 23 Feb 2012, 15:43
by Kloot
MR.D wrote:Isn't it just the format limitation in spring?
Yes and no.

Per-piece textures are not natively supported because the SJ's did not design the S3O format with that in mind (which cannot now be changed in a backward-compatible way), and consequently the rendering code was not changed to support it either.

However, Spring still is an RTS engine that potentially has to draw thousands of models at once (unlike Half-Life...), and using per-piece textures would be much slower. I thought about throwing in ppt's when writing the OBJ model loader, but decided against it. (Spring could generate per-model atlases, but those might easily grow too large.)

What is efficient for artists is unfortunately not always efficient for an engine.

Re: Importing multiple textures in a single model

Posted: 23 Feb 2012, 16:07
by Pxtl
Really, I'd rather see full-out support for modular units (that is, loading model X for piece Y) rather than PPTs. Obviously it would be a performance hit for large swarms, but for rare units like the ZK commanders it would be a dream.

Re: Importing multiple textures in a single model

Posted: 02 Mar 2012, 04:55
by SpliFF
Following Kloots comments I'm inclined to agree this isn't worth the effort (for reasons other than not having the time). A typical small model may have 5 - 10 pieces so in a game with 1000 units you immediately jump from from 1000 rendering passes to 5k-10k passes. This creates a 5x to 10x rendering hit even for games with single textured models.

Pxtl's idea of using models as pieces is actually doable already using the firetransport capability (a unit can be transported by another unit from an attach point). I've tried this using units as turrets and it actually works surprisingly well - especially if you make the attached unit unselectable.

I suppose this could be streamlined by using a metafile to load a piece from your multi-textured model as a standalone model as well as selecting a texture by name that's linked or embedded in the file. In other words you keep all your pieces and textures together in one model file but let Spring pick it apart to make new models - then use lua to glue them back together as firetransports. The only missing piece in that process right now is the ability to select a texture referenced or embedded in a model and that's not particular hard since Assimp already allows that.

Re: Importing multiple textures in a single model

Posted: 02 Mar 2012, 09:10
by Beherith
Beherith wrote:A solution to that is to merge the textures in photoshop, and the transform the UV space for each piece or model accordingly.

The following code is in python and supports .OBJ files only:

Code: Select all

print 'linear transform a model`s uv space, by Beherith (mysterme@gmail.com)'
print 'usage: python uv_linear_transform_obj.py [modelname.obj] [a] [b] [c] [d] [newmodelname.obj]'
print 'where A is the multiplier and B is the offset of the U coords'
print 'and   C is the multiplier and D is the offset of the V coords'
print 'Unew=U*a+b 	Vnew=V*c+d'
import sys
infile=open(sys.argv[1],'r').readlines()
outfile=open(sys.argv[6],'w')
a=float(sys.argv[2])
b=float(sys.argv[3])
c=float(sys.argv[4])
d=float(sys.argv[5])
for line in infile:
	if 'vt' in line:
		linesplit=line.split()
		u=float(linesplit[1])
		v=float(linesplit[2])
		u2=a*u+b
		v2=c*v+d
		outfile.write('vt '+str(u2)+' '+str(v2)+'\n')
	else:
		outfile.write(line)
print 'Done!'
Enjoy!