Is it possible to give Texture to Furniture?

This topic has been viewed 5808 times and has 7 replies
Thread status: Active
Features you would like to see [img]http://www.sweethome3d.com/images/flags/en_small.gif[/img]
Post Reply New Topic
nightrain
Posts: 4
Joined: Sat Feb 06, 2010 10:44 am

Is it possible to give Texture to Furniture?

Post by nightrain »

this is my only wish about sweethome, after this feature, this programm will be perfect!! to give texture to the furniture!
User avatar
alied
Posts: 40
Joined: Tue Sep 08, 2009 9:53 pm
Country: Rosario, Santa Fe, Argentina

Re: Is it possible to give Texture to Furniture?

Post by alied »

1- It is possible to have the texture already on the model, which would be a static texture, but I guess that is not what you mean.
2- A plug-in could be done so you can change a texture on a furniture. It is not that difficult:
-Scan the model J3D tree and put all material defined on a list.
-Change the desired texture.
-Make a UI to do the above and select the texture.
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Is it possible to give Texture to Furniture?

Post by Puybaret »

Hum... you would have to generate UV texture coordinates too. [;)]
Java 3D has something to help you generate some default UV coordinates but I don't how well it works.
Emmanuel Puybaret, Sweet Home 3D creator
User avatar
alied
Posts: 40
Joined: Tue Sep 08, 2009 9:53 pm
Country: Rosario, Santa Fe, Argentina

Re: Is it possible to give Texture to Furniture?

Post by alied »

Well, that was a rough outline. I've changed textures on-the fly, but I've allways tried to have a dummy texture before (to know where to do the change) with a named material.

Code: Select all

private void deepUpdateMaterial(Node node) {
	if (node instanceof Group) {
		Group bg = (Group) node;
		for (int i = 0; i < bg.numChildren(); i++) {
			Node shape = bg.getChild(i);
			deepUpdateMaterial(shape);
		}
	} else if (node instanceof Shape3D) {
		Shape3D shape = (Shape3D) node;
		Appearance material = shape.getAppearance();
		if (material != null) {
			shape.setAppearanceOverrideEnable(true);
			String texture = null;
/*
Here, set the texture to whatever is to set
*/
			if (texture != null) {
				BufferedImage textureImage = null;
				try {
					textureImage = ImageIO.read(new URL(texture));
				} catch (IOException ex) {
					// Ignore images at other format
				}
				if (textureImage != null) {
					TextureLoader textureLoader = new TextureLoader(textureImage, TextureLoader.GENERATE_MIPMAP | TextureLoader.BY_REFERENCE);
					material.setCapability(Appearance.ALLOW_TEXTURE_ATTRIBUTES_WRITE);
					material.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
					material.setTexture(textureLoader.getTexture());
				}
			}
		}
	}
}
That is how I do it, and it works. Emmanuel, some of this code would seem familiar to you :-). Anyway, in this case there is already a defined material. If there weren't any, you should have to list all shapes and assign a texture for each, and create materials as needed.

Why not to post this to the developpers forum, in case someone wants to try?
nightrain
Posts: 4
Joined: Sat Feb 06, 2010 10:44 am

Re: Is it possible to give Texture to Furniture?

Post by nightrain »

I am a simple user buddies :) I mean it in this way; you can easily change the texture of walls or floor, because there is a option on the menu ( you can change color or texture of walls) but on furnitures, there is only the option to change the color. is it not possible to add the texture option also to the furnitures? most importantly, to the boxes, because I create new furnitures with boxes :)
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Is it possible to give Texture to Furniture?

Post by Puybaret »

Texture on boxes is an other simpler story and a wizard that will let you create parallelepipeds with images on each face should be available soon.
Emmanuel Puybaret, Sweet Home 3D creator
User avatar
alied
Posts: 40
Joined: Tue Sep 08, 2009 9:53 pm
Country: Rosario, Santa Fe, Argentina

Re: Is it possible to give Texture to Furniture?

Post by alied »

Do you mean to apply a texture to the WHOLE model? It's simpler on the User interface part only. Inside there is no much difference.
So far, there is a tip:
sh3d files are actually zip files (technically they are jar files, wich in turn are zip files with specific parameters). You can replace a texture by opening it with any zip utility and replacing the desired texture with the new one, provided you keep the name and format.
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Is it possible to give Texture to Furniture?

Post by Puybaret »

For your information, applying texture to furniture models will be available in next version 2.3.
If you're interested, you can text this feature in current Beta version.
Emmanuel Puybaret, Sweet Home 3D creator
Post Reply New Topic

Who is online

Users browsing this forum: No registered users and 1 guest