Jump to content

Check if a texture exists


Recommended Posts

Is there a way to check if a file texture exists and if not, make it try to load another one?

For example in a texture slot, I have set it to look for a "$HIP/Texture/texture.1.rat", in case that it doesn't exist it tries to search for "texture.2.rat" so on and so forth.

Is it possible?

Edited by tomhanks
Link to comment
Share on other sites

You could accomplish this using some sort of pre-render script using opextern and opchange to find missing files. Basically trap the output of opextern to see what files don't exist, then try and replace occurrences of those string file paths in the associated parameters using opchange with texture files that do exist. You'd probably want to store the files you changed so you can revert back to them in a post-render script. Python is probably the best way to do it.

Link to comment
Share on other sites

Thanks for the reply

I didn't know that use all the resources that you have to solve a problem was a bad habit, I really didn't, if it is I am sorry it wasn't my intention to harm any forum rules.

About the help that I am asking, thanks for the reply for you both, I'll try that, but I was hoping that houdini could have some function that I could use with an "if" statement that could check if that file exists, if not it would look for a higher number on the file name, like "text.1.tif" and on.

I want to form a image with a grid with instances with textures on it, each texture would represent a color average, that's why the search for a file if it doesn't exist, so it can load a approximated color averaged texture.

I hope that I could be clear about my goal, my English doesn't help too much, but if someone have some tip about I would appreciate it.

Thanks.

Link to comment
Share on other sites

Don't worry, it's not about harming, it's about less noise==better help. Most people visit both places so give us a chance :)

As to your question, I suppose you can write your own expression to do that: "find first existing texture based on input texture and return it". It can be relatively easy to accomplish, but it smells strange to me :unsure:.

Link to comment
Share on other sites

Maybe the end justify the means :D , but I also agree it´s strange, it´s difficult even for me to explain what I really want to achieve.

That´s the result I want.

post-4542-125678563833_thumb.jpg

I think the picture talks for itself.

But I want to use live action footage to form my final picture so it would update at each frame.

My first Idea was to put a texture in to the points color in a grid and for each point I would have a RGB value which I would use call my texture like if I have 100% green my texture for it would be something like "texture.0_1_0.tif", the "0_1_0" would be an attribute procedurally created from my point color.

I wouldn't have all the textures for all the values in RGB, so that´s why my need to search for the most approximate texture to my actual point value.

There´s also a issue to build this texture database, but I think with COPs I can do it.

I don't know if I could explain it right, but if there´s a better and simple idea for that it would be welcome.

Anyway thanks for the help, and sorry for the confusing thread.

Link to comment
Share on other sites

One idea to do the matching is via the AttribTransfer SOP.

So here's a rough sketch:

  • Create two point clouds, a set of points representing your picture ("picture cloud"), and another set of points representing your textures ("texture cloud")
  • For the "picture cloud", set the Cd values into their positions.
  • For the "texture cloud", create a point for every texture that you have such that their position is the color of the texture. Add a string attribute that records the original file name. Add another integer attribute (called "ptnum" say) that just records $PT.
  • Use the AttribTransfer SOP with a "Uniform" (kernel?) on it to transfer the "ptnum" attribute from the "texture cloud" to the "picture cloud". You might need to play with the distance threshold.
  • Now you should be able to lookup "ptnum" on your "picture cloud" to index back into the "texture cloud" to determine which texture to use.

Having created these types of images before (using a specialized program back in Univ). Some thoughts on getting a better quality result:
  • You need a *huge* amount of textures in order to approximate the picture. (Where are those people who have downloaded all of Flickr? :) )
  • A cheap trick is to overlay your original picture on top of the result with some alpha to "improve" the look :)
  • Doing it at the per picture pixel level isn't really enough. You need subsampling. eg. Treat each texture not as 1 pixel color, but say as 2x2 (or 3x3, etc) pixel colors. Now you match these 4 color values per texture against a scaled up version your picture at the final result size.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...