Can I "store" a material as object in a variable?
-
I want to know if I can load a material inside variable and use it in sketchup. (I know, variables in ruby are pointers, they don't actually STORE data)
Using this:
model = Sketchup.active_model mats = model.materials mat = mats[0] mat
Will return me the reference; the ID of material
#<Sketchup::Material:0x68577b8>
, not the actual material. If I delete the material from sketchup (or disk) just after I get that, that reference will not longer be valid.
Something like materials are stored inside sketchup file...
If this can be possible, then materials can be stored in a database (or other kind of similar file) and passed from there directly to sketchup. For now, the only idea I have is to encode the skm file in base64, store it as ascii string in database, then when needed, decode it in a temp folder, from where to be picked up by Sketchup, then deleted from temp file.Any better ideas?
-
hm... the issue here is the bitmap data for the texture, right? I was thinking of that myself today - would be nice if SU had a method to return that data - instead of writing it to a temp file and reading it again...
As for your question, I don't see any way without writing out to temp files - since we can't get or set the raw bitmap data.
-
VisMap does a 6-bit string encode in JavaScript, decodes in Ruby. Go ahead and steal mine, but please attribute correctly.
Link is on my site, top-right corner.
-
@martinrinehart said:
VisMap does a 6-bit string encode in JavaScript, decodes in Ruby. Go ahead and steal mine, but please attribute correctly.
Link is on my site, top-right corner.
But how this solves what thomthom said? He is true: we need a way to pass raw bitmap data inside sketchup. The only other method is with the temp folder.
-
@martinrinehart said:
VisMap does a 6-bit string encode in JavaScript, decodes in Ruby. Go ahead and steal mine, but please attribute correctly.
Link is on my site, top-right corner.
You're talking about passing the material name?
It's not the material name, but all the data the belongs to the material - which include the texture data. -
@newone said:
For now, the only idea I have is to encode the skm file in base64, store it as ascii string in database, then when needed, decode it in a temp folder, from where to be picked up by Sketchup, then deleted from temp file.
You could do that, but there is also no way to load the .skm file from Ruby.
Could the TextureWriter be used to write the data to a string?
-
@jim said:
You could do that, but there is also no way to load the .skm file from Ruby.
doh!
Ok - in that case: export the texture bitmap and base64 encode/decode that. Which means you have to do extra work to extract the rest of the data for the Material and Texture objects.
-
With IE8 being able to use data URIs (although limited to 32k) it was very tempting to send texture data directly to webdialogs. But since SU doesn't return the bitmap data I'd have to write to file. And then there's no point in base64 encode it - I can just link to the temp file.
I think this issue is worthy of a feature request.
-
Also -there is no .skm export it seems...
multiple feature requests here it appears.
-
Well, extra data in skm (the xml file) is not necessary to be encoded. We can store the texture as base64 and tiling, alpha as some parameters. And the material to be created inside ruby.
So the problem which stands: (how to) send raw bitmap data directly to sketchup via ruby?
-
@newone said:
Well, extra data in skm (the xml file) is not necessary to be encoded. We can store the texture as base64 and tiling, alpha as some parameters. And the material to be created inside ruby.
But there isn't any ruby API to export material to .skm, right? Or have I missed something?
@newone said:
So the problem which stands: (how to) send raw bitmap data directly to sketchup via ruby?
Again, you have to save a temp file and load it.
-
QUESTION: Does ruby have some debug methods which show the content of an object? If do, we could access what is behind of
#<Sketchup::Material:0x6732f80>
and do whatever we want wit that data. And I assume that the reverse could be possible as well. -
@newone said:
QUESTION: Does ruby have some debug methods which show the content of an object? If do, we could access what is behind of
#<Sketchup::Material:0x6732f80>
and do whatever we want wit that data. And I assume that the reverse could be possible as well.The Material object won't contain the bitmap data. It's more like a pointer to the interal SU data.
-
I found this http://www.imagemagick.org/RMagick/doc/#introduction Maybe is a way to have the texture image as blob inside ruby. If so, making the skm material with script is the easy part and can skip the part with "temp folder"
If any of you have time, throw an eye over it. -
@newone said:
I found this http://www.imagemagick.org/RMagick/doc/#introduction Maybe is a way to have the texture image as blob inside ruby. If so, making the skm material with script is the easy part and can skip the part with "temp folder"
If any of you have time, throw an eye over it.The whole reason we need to write to temp file is to get to the bitmap data in the first place.
-
Yes, I just noticed that is no use to have bitmap data as binary in ruby. Because when asigning texture image to a created material
m = materials.add "mat1" m.texture = "C;/texure.jpg"
We don't really add that texture, but pass the path to SketchUp and there, inside that evil thing some magic happens and it grabs the texture with the claws. So, yes... we need the bitmap as file on disk before any attempt to do anything.
Advertisement