SketchUcation Plugin Store

 

 

[Plugin] Image 2 Model

[Plugin] Image 2 Model

Postby EarthMover » Fri Apr 06, 2012 3:38 pm

Looking for a script to take a folder off the hard drive and batch convert transparent .png files to .skp with a 0,0,0 axis and face camera enabled. A bonus would be if it would hide the perimeter edges of the image. It's not necessary to cut them out for shadows as they will be rendered. Just looking to speed up the conversion process as I have hundreds of plant images that I've taken and isolated and the manual conversion is becoming quite tedious. Not sure if something already exists. Any help would be much appreciated.

EDIT - Much thanks to SDMitch! Most recent plugin attached.
Please, register (free) to access all the attachments on the forums.
Last edited by EarthMover on Tue Apr 17, 2012 1:40 pm, edited 2 times in total.
A designer is an emerging synthesis of artist, inventor, mechanic, objective economist and evolutionary strategist. - R. Buckminster Fuller
Some of my 3D crap
User avatar
EarthMover
Top SketchUcator
 
Posts: 1792
Joined: Fri Sep 12, 2008 9:06 pm
Location: Eastern Pennsylvania
Name: Adam Hails

Re: {REQ} Batch Import .png to .skp face camera

Postby sdmitch » Sat Apr 07, 2012 6:41 pm

Am I correct in assumming that you want each image in its on .skp file and placed at the origin?

Images are included in a model's definitions but I don't think the .behavior.always_face_camera applies. I believe it only applies to components.
Nothing is worthless, it can always be used as a bad example.

http://sdmitch.blogspot.com/
User avatar
sdmitch
 
Posts: 617
Joined: Wed Mar 02, 2011 9:21 pm
Name: Sam
Operating system: Windows
SketchUp version: 8
License type: Free
SketchUp use: hobby
Level of SketchUp: Beginner

Re: {REQ} Batch Import .png to .skp face camera

Postby Gaieus » Sat Apr 07, 2012 8:03 pm

In such a case, images should be exploded and the face (bearing the image material) turned into such a component.

You can turn an image entity into a component, too (and face to the camera) but that would cause all sorts of issues with external renderers as not each can recognise image entities at all.


Now the ultimate question (if such a script were possible): how to scale those components?
Gai...
User avatar
Gaieus
Administrator
 
Posts: 27626
Joined: Sat Oct 20, 2007 8:24 am
Location: Pécs, Hungary
Name: Csaba Pozsárkó
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: historical reconstruction
Level of SketchUp: Advanced

Re: {REQ} Batch Import .png to .skp face camera

Postby sdmitch » Sun Apr 08, 2012 1:41 am

Adam, Would you post an image that I could test. I have been working on your plugin and I want see if it works the same with one of your images as it does with mine.

Gaieus has a point regarding sizing the images/components.
Nothing is worthless, it can always be used as a bad example.

http://sdmitch.blogspot.com/
User avatar
sdmitch
 
Posts: 617
Joined: Wed Mar 02, 2011 9:21 pm
Name: Sam
Operating system: Windows
SketchUp version: 8
License type: Free
SketchUp use: hobby
Level of SketchUp: Beginner

Re: {REQ} Batch Import .png to .skp face camera

Postby TIG » Sun Apr 08, 2012 11:10 am

You set the image size as you import it, but you can reset it later after reading its pixel sizes and basing the inch sizes on those, pro-rata...
The basic code to add an image is:
image-entities.add_image(path_to_file, insertion_point, width, [height])
The width/height are in inches.
The last argument [height] is optional, if omitted it is taken as being in proportion to the width you have set.
An added image typically arrives 'flat' at the ORIGIN - if it's a plant or tree you'll probably want to stand it up on its end - you can apply a simple rotation transformation:tr=Geom::Transformation.rotation(ORIGIN,X_AXIS,90.degrees)
image.transform!(tr)

You might also want to shunt the image so that the center of its bas is at the ORIGIN rather than it bounds.min ? Here a simple translation is needed:
tr=Geom::Transformation.translation([image.width/2,0,0].vector_to([0,0,0]))
image.transform!(tr)
TIG
User avatar
TIG
Global Moderator
 
Posts: 13987
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: {REQ} Batch Import .png to .skp face camera

Postby sdmitch » Sun Apr 08, 2012 4:00 pm

TIG, Great minds think alike. I originally tried moving the Image bottom center to the Model ORIGIN before making it first a Group then a Component but didn't change the point the Image rotated about when Orbiting. I had to move the Component.transformation.origin instead.

One thing that I can't seem to resolve is the fact that although I do a "viewFront:" and a "viewZoomExtents:" before doing the .save, the model, when opened, has not been saved that way.
Nothing is worthless, it can always be used as a bad example.

http://sdmitch.blogspot.com/
User avatar
sdmitch
 
Posts: 617
Joined: Wed Mar 02, 2011 9:21 pm
Name: Sam
Operating system: Windows
SketchUp version: 8
License type: Free
SketchUp use: hobby
Level of SketchUp: Beginner

Re: {REQ} Batch Import .png to .skp face camera

Postby EarthMover » Mon Apr 09, 2012 12:37 am

sdmitch wrote:Adam, Would you post an image that I could test. I have been working on your plugin and I want see if it works the same with one of your images as it does with mine.

Gaieus has a point regarding sizing the images/components.


Here is one of my hi-res .png files for testing.

Yes, I did forget to mention a few steps. The routine is -

1. Import and place 'image' in front viewport.

2. Center on axis as pivot point

3. Explode image

4. Select all

5. Make Component (Check always face camera, shadows face sun

6. Enter component edit and select outer edges and hide them.

7. Exit component and 'Save as' image name.

Thanks for looking into it Sam and for the help TIG. If something can be manifested it would save hours of tedious work.
Please, register (free) to access all the attachments on the forums.
A designer is an emerging synthesis of artist, inventor, mechanic, objective economist and evolutionary strategist. - R. Buckminster Fuller
Some of my 3D crap
User avatar
EarthMover
Top SketchUcator
 
Posts: 1792
Joined: Fri Sep 12, 2008 9:06 pm
Location: Eastern Pennsylvania
Name: Adam Hails

Re: {REQ} Batch Import .png to .skp face camera

Postby sdmitch » Mon Apr 09, 2012 3:41 pm

Adam, Your image worked exactly like mine so I have attached Image 2 Model I. When you execute the plugin, The Open panel will allow you to select the source folder for the images. Next, the Save panel will allow you to select the destination folder for the models. An inputbox will let you choose whether the image is to be "stood up" and the width for the images. Since this is a "batch" process these options will be applied to all images in the source folder.

I still haven't resolved the problem of the saved file not being frontview and zoomed extents. It seems that it saves the model however the default template is setup.

Check it out and let me know how it worked for you.
Please, register (free) to access all the attachments on the forums.
Nothing is worthless, it can always be used as a bad example.

http://sdmitch.blogspot.com/
User avatar
sdmitch
 
Posts: 617
Joined: Wed Mar 02, 2011 9:21 pm
Name: Sam
Operating system: Windows
SketchUp version: 8
License type: Free
SketchUp use: hobby
Level of SketchUp: Beginner

Re: {REQ} Batch Import .png to .skp face camera

Postby EarthMover » Mon Apr 09, 2012 4:39 pm

Works great with one exception. Can you perhaps set it to save just the newly created component and not save a copy of "Susan" along with each new .skp? Perhaps that's is the issue you are already referring to. I need to be able to compile these plants through the component folder. Other than that it's working like a charm!! :D

Also, just noticed that the component is still an "image". Possible to explode that down before the component conversion? Not sure if the final .skp files will work with all render engines with 'images' embedded.
A designer is an emerging synthesis of artist, inventor, mechanic, objective economist and evolutionary strategist. - R. Buckminster Fuller
Some of my 3D crap
User avatar
EarthMover
Top SketchUcator
 
Posts: 1792
Joined: Fri Sep 12, 2008 9:06 pm
Location: Eastern Pennsylvania
Name: Adam Hails

Re: {REQ} Batch Import .png to .skp face camera

Postby sdmitch » Mon Apr 09, 2012 4:58 pm

If Susan is showing up it because she is in your default template.

I take a look at exploding.
Nothing is worthless, it can always be used as a bad example.

http://sdmitch.blogspot.com/
User avatar
sdmitch
 
Posts: 617
Joined: Wed Mar 02, 2011 9:21 pm
Name: Sam
Operating system: Windows
SketchUp version: 8
License type: Free
SketchUp use: hobby
Level of SketchUp: Beginner

Re: {REQ} Batch Import .png to .skp face camera

Postby TIG » Mon Apr 09, 2012 5:29 pm

You could always some code at the start to erase all model entities...
Sketchup.active_model.entities.erase_entities(Sketchup.active_model.entities.to_a)
[or a Sketchup.active_model.entities.clear [edit]]
Then .purge_unused for all model components, materials, layers and styles before adding the new image into the now sanitized model.
Surely image.explode will do the desired extra step ?
TIG
User avatar
TIG
Global Moderator
 
Posts: 13987
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: {REQ} Batch Import .png to .skp face camera

Postby sdmitch » Mon Apr 09, 2012 5:41 pm

Added a .clear! to make sure the new file is empty. Exploded the image and hide the edges.
Please, register (free) to access all the attachments on the forums.
Nothing is worthless, it can always be used as a bad example.

http://sdmitch.blogspot.com/
User avatar
sdmitch
 
Posts: 617
Joined: Wed Mar 02, 2011 9:21 pm
Name: Sam
Operating system: Windows
SketchUp version: 8
License type: Free
SketchUp use: hobby
Level of SketchUp: Beginner

Re: {REQ} Batch Import .png to .skp face camera

Postby TIG » Mon Apr 09, 2012 5:49 pm

The 'entities.clear' only erases the instance of Susan [and any other stuff placed in the default template].
BUT the definition still remains in the SKP, as do any now-unused related materials, layers etc.
It's best to have a '.purge_unused' for these after the '.clear'...
TIG
User avatar
TIG
Global Moderator
 
Posts: 13987
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: {REQ} Batch Import .png to .skp face camera

Postby sdmitch » Mon Apr 09, 2012 5:54 pm

I haven't been able to find .purge_unused.

sorry, I did find it for materials and styles.

Searching returned no results.
Nothing is worthless, it can always be used as a bad example.

http://sdmitch.blogspot.com/
User avatar
sdmitch
 
Posts: 617
Joined: Wed Mar 02, 2011 9:21 pm
Name: Sam
Operating system: Windows
SketchUp version: 8
License type: Free
SketchUp use: hobby
Level of SketchUp: Beginner

Re: {REQ} Batch Import .png to .skp face camera

Postby TIG » Mon Apr 09, 2012 8:26 pm

TIG
User avatar
TIG
Global Moderator
 
Posts: 13987
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: {REQ} Batch Import .png to .skp face camera

Postby sdmitch » Mon Apr 09, 2012 8:48 pm

I did the search, .purge_unused, at

https://developers.google.com/sketchup/docs/

which is the Ruby API page and it found nothing. Apparently it was the "." that cause the failed search. Lots of results without it.
Nothing is worthless, it can always be used as a bad example.

http://sdmitch.blogspot.com/
User avatar
sdmitch
 
Posts: 617
Joined: Wed Mar 02, 2011 9:21 pm
Name: Sam
Operating system: Windows
SketchUp version: 8
License type: Free
SketchUp use: hobby
Level of SketchUp: Beginner

Re: [Plugin] - Image 2 Model

Postby EarthMover » Tue Apr 17, 2012 1:31 pm

First post updated with [plugin] tag.

Got a bit busy and haven't had a chance to truly say thanks! SDMitch, I owe you a beer! Plugin works great. Thanks again! :berserk:
A designer is an emerging synthesis of artist, inventor, mechanic, objective economist and evolutionary strategist. - R. Buckminster Fuller
Some of my 3D crap
User avatar
EarthMover
Top SketchUcator
 
Posts: 1792
Joined: Fri Sep 12, 2008 9:06 pm
Location: Eastern Pennsylvania
Name: Adam Hails

Re: {REQ} Batch Import .png to .skp face camera

Postby guanjin » Tue Apr 17, 2012 6:27 pm

sdmitch wrote:Added a .clear! to make sure the new file is empty. Exploded the image and hide the edges.


I opened the PNG image, the view does not show
I come from China, is to learn
User avatar
guanjin
 
Posts: 190
Joined: Thu Apr 08, 2010 6:52 am
Name: XIAOLONG
Operating system: Windows
SketchUp version: 8
License type: Free
SketchUp use: interior design
Level of SketchUp: Intermediate

Re: [Plugin] - Image 2 Model

Postby coreymurray » Wed Apr 25, 2012 10:38 pm

Just wanted to say thanks for this plugin, it really is super helpful!
coreymurray
 
Posts: 9
Joined: Thu Dec 20, 2007 2:59 am

Re: [Plugin] - Image 2 Model

Postby irwanwr » Sun Aug 12, 2012 2:03 pm

Thank you all, I'll try to learn how to use this.
Might be better to place face me comps rather than just placing them in post pro mostly.

Does this script function also available in SKM Tools by TIG. Sorry sir, just curious.
User avatar
irwanwr
 
Posts: 571
Joined: Fri May 21, 2010 2:21 am
Location: Medan, Indonesia.
Name: irwanwr
Operating system: Windows
SketchUp version: 8
License type: Free
SketchUp use: hobby
Level of SketchUp: Beginner

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Artisan Organic Toolset - a set of powerful organic modeling tools.

Premium Members get 20% discount!

Ad Machine
Robot
 
Posts: 2012


Return to Plugins

Who is online

Users browsing this forum: Capenti, feodos, Macker, noro, radiacor, stefanq and 10 guests