Components and instancing in 1.025

Forums: Components and instancing in 1.025
SketchUp Integrated Plugin (Integrated Plugin maintained by OTOY)

Re: Components and instancing in 1.025

Postby smicha » Thu Aug 02, 2012 11:19 am

smicha Thu Aug 02, 2012 11:19 am
smicha wrote:1 0 0 2 0 1 0 3 0 0 1 4

First, sixth, eleventh ones must be equal to one - they are responsible for scaling along X Y Z axes respectively (or X Z Y in octane, ZY swapped)


TIG,
Sorry again :) These ones don't have to be equal to 1 if we scale individuals in Sketchup.
3090, Titan, Quadro, Xeon Scalable Supermicro, 768GB RAM; Sketchup Pro, Classical Architecture.
Custom alloy powder coated laser cut cases, Autodesk metal-sheet 3D modelling.
build-log http://render.otoy.com/forum/viewtopic.php?f=9&t=42540
User avatar
smicha
Licensed Customer
Licensed Customer
 
Posts: 3151
Joined: Wed Sep 21, 2011 4:13 pm
Location: Warsaw, Poland

Re: Components and instancing in 1.025

Postby smicha » Thu Aug 02, 2012 12:21 pm

smicha Thu Aug 02, 2012 12:21 pm
TIG wrote:Put the code into a .rb file and load it in the Ruby Console.
To test export an OBJ of an instance placed at the origin, that's neither rotated nor scaled.
Place some more instances and select one and type in the Ruby Console to run it...
csv_test

To make it truly 'CSV' seen the 'sprintf' note in the code.


TIG,
I've never done ruby scripts before. Could you please give me more instructions how to upload the script? I downloaded ruby web console, pasted your code, saved it and hit EVAL and .... what should I do ? See my screenshot.
Attachments
rb.jpg
3090, Titan, Quadro, Xeon Scalable Supermicro, 768GB RAM; Sketchup Pro, Classical Architecture.
Custom alloy powder coated laser cut cases, Autodesk metal-sheet 3D modelling.
build-log http://render.otoy.com/forum/viewtopic.php?f=9&t=42540
User avatar
smicha
Licensed Customer
Licensed Customer
 
Posts: 3151
Joined: Wed Sep 21, 2011 4:13 pm
Location: Warsaw, Poland

Re: Components and instancing in 1.025

Postby TIG » Thu Aug 02, 2012 4:09 pm

TIG Thu Aug 02, 2012 4:09 pm
Forget Web Console etc.
Use the Ruby Console from the Sketchup Menu > Window...

Any file with a .rb file-extension that's in the Plugins folder will auto-load as Sketchup starts.
Or if it's added later or it's in a subfolder you can type a load command in the Console.
load "test.rb"
or
load "smicha/test.rb"
if you've made a subfolder.
If you change and save you code you can simply reload it with the same 'load' command again without needing to restart Sketchup.

To make the script use PC's Notepad.exe or equivalent plain-text editor - never a wordprocessor.
Save it as say "test.rb" - note the file-extension.
Copy paste the code I gave into the file and save.
Adjust the code as needed to get the right results needed for the OCS.
To save the file as something other than ".CSV" just change the suffix added to the 'file' in the code - e.g. ".TXT"***

To run this test method it's not wrapped in a module or class for simplicity...
To use it ensure it's loaded, then select an instance in the [saved] SKP and in the Ruby Console type
csv_test
to run it...
The transformations are saved into a file with the SKP...

***You might want to think about changing the method's title to something without 'csv' in it if there are no Commas :roll:
TIG
User avatar
TIG
Licensed Customer
Licensed Customer
 
Posts: 536
Joined: Wed May 12, 2010 1:25 pm

Re: Components and instancing in 1.025

Postby smicha » Fri Aug 03, 2012 9:42 am

smicha Fri Aug 03, 2012 9:42 am
TIG,
Almost done ! One correction is needed - an object is rotated 90deg. Yellow Ls come from SU, white ones from the scatter.

I was playing with changing an order of elements in a single row but with no results. The first row is
1 0 0 0 | 0 0 1 0 | -0 -1 -0 1
and should be
1 0 0 0 | 0 1 0 0 | 0 0 1 0,

The second is
0.8965 0.4431 0 -1.8348 0 -0 1 0 0.4431 -0.8965 -0 1.4875
and should be...?

How to set a correct order to rotate the object properly? I am attaching .ocs.

Thank you so much again.
Attachments
scaterL.jpg
L.rar
(7.15 KiB) Downloaded 321 times
3090, Titan, Quadro, Xeon Scalable Supermicro, 768GB RAM; Sketchup Pro, Classical Architecture.
Custom alloy powder coated laser cut cases, Autodesk metal-sheet 3D modelling.
build-log http://render.otoy.com/forum/viewtopic.php?f=9&t=42540
User avatar
smicha
Licensed Customer
Licensed Customer
 
Posts: 3151
Joined: Wed Sep 21, 2011 4:13 pm
Location: Warsaw, Poland

Re: Components and instancing in 1.025

Postby TIG » Fri Aug 03, 2012 9:51 am

TIG Fri Aug 03, 2012 9:51 am
As I said in my sample code I am unsure of the ordering of the OCS matrix.
We have all of the info in the SKP matrix
Code: Select all
r,r,r,0
r,r,r,0
r,r,r,0
x,y,z,1
The right column is 'ignored'...
While the OCS matrix is something like
Code: Select all
r,r,r,x
r,r,r,y
r,r,r,z
AND the y and z are transposed - the SKP y >>> z and z >>> -y ?
The 'r' is a rotation/scaling 'factor'...
I assume these are NOT in the same order in the two versions...
TIG
User avatar
TIG
Licensed Customer
Licensed Customer
 
Posts: 536
Joined: Wed May 12, 2010 1:25 pm

Re: Components and instancing in 1.025

Postby smicha » Fri Aug 03, 2012 10:25 am

smicha Fri Aug 03, 2012 10:25 am
TIG,
This is not a matter of the order only - I was playing with different orders of elements. Look at the first row: there are four ones, should be three of them:

This sequence
1 0 0 0 | 0 0 1 0 | -0 -1 -0 1

cannot be arrange into

1 0 0 0 | 0 1 0 0 | 0 0 1 0.
3090, Titan, Quadro, Xeon Scalable Supermicro, 768GB RAM; Sketchup Pro, Classical Architecture.
Custom alloy powder coated laser cut cases, Autodesk metal-sheet 3D modelling.
build-log http://render.otoy.com/forum/viewtopic.php?f=9&t=42540
User avatar
smicha
Licensed Customer
Licensed Customer
 
Posts: 3151
Joined: Wed Sep 21, 2011 4:13 pm
Location: Warsaw, Poland

Re: Components and instancing in 1.025

Postby TIG » Fri Aug 03, 2012 3:29 pm

TIG Fri Aug 03, 2012 3:29 pm
Reread my last post...

The SKP matrix has all of the data we need - we just need to find what needs to become what in the OCS version.
The SKP's matrix's right-hand [4th] column 0,0,0,1 is 'ignored' by Sketchup - it might be somehow used in the OCS one??
Then the x/y/z need to become x/-z/y for the OCS [Y and Z are flipped and the z needs to be made -ve to then be in the correct direction ?] ... AND these are arranged in the OCS matrix's 3rd column too.
The top left-corner's 9 'r' entries [3x3] of the SKP's matrix represent the rotation/scaling/mirroring factors.
They are probably somewhat similar in the OCS matrix - perhaps reordered yet again...
Because you example is in 0s and 1s it's impossible to tell which values are 'transposed' between the two versions.
Can you make a SKP and OCS version and compare the matrices ?
Perhaps with a 'zeroed' instance and once that's offset by 2 not 1 etc... :?
TIG
User avatar
TIG
Licensed Customer
Licensed Customer
 
Posts: 536
Joined: Wed May 12, 2010 1:25 pm

Re: Components and instancing in 1.025

Postby smicha » Fri Aug 03, 2012 4:20 pm

smicha Fri Aug 03, 2012 4:20 pm
TIG,
All files are attached - SKP and OCS. I did my best to match appropriate values in scatter data - no success. Sorry.
Could you please try to match white and yellow objects? I appreciate your help.
Attachments
scatter.rar
(69.59 KiB) Downloaded 345 times
3090, Titan, Quadro, Xeon Scalable Supermicro, 768GB RAM; Sketchup Pro, Classical Architecture.
Custom alloy powder coated laser cut cases, Autodesk metal-sheet 3D modelling.
build-log http://render.otoy.com/forum/viewtopic.php?f=9&t=42540
User avatar
smicha
Licensed Customer
Licensed Customer
 
Posts: 3151
Joined: Wed Sep 21, 2011 4:13 pm
Location: Warsaw, Poland

Re: Components and instancing in 1.025

Postby TIG » Fri Aug 03, 2012 9:26 pm

TIG Fri Aug 03, 2012 9:26 pm
Try this - the problem is turning the SKP's column based 16 element matrix into the OCS's 'row-major 12 element matrix
Code: Select all
require 'sketchup.rb'
###
def txt_test()
model=Sketchup.active_model
instances=model.selection[0].definition.instances
###
txt=""
instances.each{|instance|
  tr=instance.transformation.to_a
  tt=[tr[0],tr[4],tr[8],tr[12].to_m, tr[2],tr[6],tr[10],-(tr[14]).to_m, tr[1],tr[5],tr[9],tr[13].to_m]
  str=""
  tt.each{|e| str<<sprintf("%.4f ",e) }
  ### "%.4f," for a Comma
  txt<<str+"\n"
}
###
path=File.dirname(model.path)
file=File.join(path, model.title+"_"+instances[0].definition.name+".TXT").tr("\\","/")
f=File.new(file, "w")
f.puts(txt)
f.close
end
As well as tr[14]... we might need to make tr[2], tr[6] and tr[10] -ve too if this is not working ... ?
Please test and report back...
Note I've changed it to 'txt_test' and the file type to TXT !!
This must be better :?
TIG
User avatar
TIG
Licensed Customer
Licensed Customer
 
Posts: 536
Joined: Wed May 12, 2010 1:25 pm

Re: Components and instancing in 1.025

Postby smicha » Sat Aug 04, 2012 10:51 am

smicha Sat Aug 04, 2012 10:51 am
TIG,
I am solving this problem for about 5-6 hours today :)
I searched for a rotation matrix and based on its construction figured out that the proper order of exported elements from skp into octane are

Code: Select all
SU:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16


Code: Select all
Octane:
0 2 -1 3
8 10 9 11
-4 6 5 7
12 14 -13 15
.

So the line responsible for exporting these elements in your code should look like:

Code: Select all
tt=[tr[0],tr[8],-(tr[4]),tr[12].to_m, tr[2],tr[10],tr[6],tr[14].to_m, -(tr[1]),tr[9],tr[5],-(tr[13]).to_m]


And it almost works! Almost means that to every copy of an component is added extra distance. And that distance is from origin of a Sketchup project [0,0,0] to origin of a certain copy of a component. So the code needs to be corrected again.

tr[12].to_m + correction, distance from origin in x direction
tr[14].to_m + correction, distance from origin in z direction (z is UP)
-(tr[13].to_m) + correction, distance from origin in ty direction.


Please take a look at screenshots.

So close ....:)
Attachments
octane.jpg
additional-displacement.jpg
su2or.jpg
3090, Titan, Quadro, Xeon Scalable Supermicro, 768GB RAM; Sketchup Pro, Classical Architecture.
Custom alloy powder coated laser cut cases, Autodesk metal-sheet 3D modelling.
build-log http://render.otoy.com/forum/viewtopic.php?f=9&t=42540
User avatar
smicha
Licensed Customer
Licensed Customer
 
Posts: 3151
Joined: Wed Sep 21, 2011 4:13 pm
Location: Warsaw, Poland
PreviousNext

Return to SketchUp


Who is online

Users browsing this forum: No registered users and 19 guests

Fri Apr 19, 2024 9:21 pm [ UTC ]