Page 2 of 6

Re: Components and instancing in 1.025

PostPosted: Wed Aug 01, 2012 4:20 pm
by rappet
rappet wrote:
TIG wrote:You sort of answer your question in the question...

You need to export individual parts of your Model as OBJ/MTL file sets - it's an available option on the SUp Exporter - i.e. 'no render'... OR if you have Pro you could use the inbuilt OBJ exporter - setting the options up correctly meters/triangulated/single-sided/flippedZY etc as required by the receiving OCS...
The SUp Exporter only includes things on visible layers [or that are not otherwise 'hidden'].
So if you have componentized your model either export the individual components as external SKPs and export those as separate OBJ/MTL files, or use on/off layers [and scene-tabs to remember them etc] in the Model to keep the relative relationships of the geometry/objects... and then export them as named sets...
Make an OCS with the latest Octane version and manually add multiple OBJ nodes etc using these named sets...
Use the new Octane functions as detailed in the other links already given to make them all active etc...


But how to make an animation when the different objects are geometrically gouped obj's?
Greetz,


I am a step further in trying making an animation of instancing nodes:
viewtopic.php?f=33&t=22508&p=100536#p100536

Re: Components and instancing in 1.025

PostPosted: Wed Aug 01, 2012 4:41 pm
by rappet
smicha wrote:
TIG wrote:Then how might you use it ?
Manually typing in for each seems tiresome in the extreme !


The idea is to upload a csv file or to paste a 12xN matrix, not to do it manually - please see a screenshot.

I don't know how to use the code you sent but if you could be so kind and write step by step instructions how to get coordinates of all or selected copies of a component I'll export it into Matlab or R-project and write my own code to transform coordinates from sketchup into 12xN matrix.


I am working on a excell to make rows and matrixes for making a csv file: works for me in Octane and does not depends on 3d-modeller.
Let me know if you think it may help and I will upload when I have finished it.
The attachments show you a tryout of a clean and scattered matrix of objects and a prntscrn (random showing clean matrix) of the excell used.

greetz

Re: Components and instancing in 1.025

PostPosted: Wed Aug 01, 2012 5:14 pm
by smicha
Rappet,
Great work in excel! My problem is just to get 2 vectors: [dx dy dz] for displacement and [rx ry rz] for rotation for each copy of a component (scale is always unchanged) and save them as txt or csv file.

So my great request to TIG is to help me how to do it (see my previous post). The rest of it - transforming the vectors into appropriate Nx12 matrix I'll do in external software - R-project.

Re: Components and instancing in 1.025

PostPosted: Thu Aug 02, 2012 8:22 am
by TIG
Is there a way to make Octane import csv information - or must you do that manually ?
It would be possible for you to do it something like this...
You select one component-instance.
You run the tool.
It makes a small OBJ/MTL file - named as the Model_Component's name - in the project's folder.
It finds all component-instances that are the same definition.
It makes a CSV file containing the location/rotation and scaling information for each.
One entry per line.
We name it after the Model_Component's name.
The OBJ and CSV are imported into the OCS and it uses the one instance multiple times...

Can you confirm the order that the CSV file's '12' entries need to be in ?
Also what they are - I assume 'meters' and YZ swapping as usual...
Do you have a simple/short example??

I'll think about the example coding and come back to you soon...

Re: Components and instancing in 1.025

PostPosted: Thu Aug 02, 2012 9:01 am
by smicha
TIG wrote:Is there a way to make Octane import csv information - or must you do that manually ?


You can upload a csv or paste the values from a file - see the screenshot.
Adding a scatter node is manual work but that's it - just one node.


TIG wrote:Can you confirm the order that the CSV file's '12' entries need to be in ?


Yes - YZ is swapped and always in meters.
If you need more info about each entry in a single line please let me know.
CSV file is attached - each entry is separated by a space.

TIG wrote: Do you have a simple/short example??


Please find files attached.

Re: Components and instancing in 1.025

PostPosted: Thu Aug 02, 2012 9:05 am
by smicha
TIG,
I my example there is no rotation - just translation. Rotation is introduced by the way that rappet shown in his excel file.

Re: Components and instancing in 1.025

PostPosted: Thu Aug 02, 2012 10:06 am
by rappet
smicha wrote:TIG,
I my example there is no rotation - just translation. Rotation is introduced by the way that rappet shown in his excel file.

indeed, but that is just a rotation around the vertical axis. I don't know how it works when rotating around other axis or combined rotations.
greetz,

Re: Components and instancing in 1.025

PostPosted: Thu Aug 02, 2012 10:11 am
by TIG
The 'CSV' you supplied is not actually a CSV [or even a TSV] = it's a SSV - Space Separated Variable file ! There are no Commas [or Tabs] in it!
What is the format needed/usable by the OCS?
Can you clarify which item in the line is which value in the OCS transformation...
These are not the same as the SKP transformation which has flipped YZ values AND I suspect it's rotated/flipped, because what found so far suggests that the last line of the 16 is redundant [items 12/13/14/15], but in a SKP it's always the last column that's 0,0,0,1 [items 3/7/11/15] - 12/13/14 are the object's x/y/z values while the top left 3x3 is the rotation/scaling weirdness...
This is how I suspect the OCS wants it - using SKP items...
Code: Select all
0,4,8,12
2,6,10,14
-1,-5,-9,-13
3,7,11,15

Where the right column becomes the bottom line [0,0,0,1==unused] and the three rows are rotation/scaling ending in OCS XYZ [swapped around from the SKP's] - not sure about -ve all of the Z >>> Y ?

So in outline code:
Code: Select all
require 'sketchup.rb'
###
def csv_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 Comma
  }
  txt<<str+"\n"
}
###
path=File.dirname(model.path)
file=File.join(path, model.title+"_"+instances[0].definition.name+".CSV").tr("\\","/")
f=File.new(file, "w")
f.puts(txt)
f.close
end
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.
Suggest you don't use a 'cube' but something like a 1m L-shape in 3d so you can judge placement/rotation/scaling/mirroring etc between the SKP and OCS versions...
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.
If the matrix is jumbled we can reassign the swaps...

Re: Components and instancing in 1.025

PostPosted: Thu Aug 02, 2012 11:00 am
by rappet
TIG wrote:The 'CSV' you supplied is not actually a CSV [or even a TSV] = it's a SSV - Space Separated Variable file ! There are no Commas [or Tabs] in it!
What is the format needed/usable by the OCS?...
...

Hi, when I open the csv file in excel and in notepad or word they can appear differently.
I worked with a csv file that has tabs or spaces (like smicha's file) and when opening in the ocs they work (without using the commas or ;).
So it look slike the format with just spaces or tabs between the numbers is sufficient.

I attached the txt files and one csv file so maybe you can see difference in appearance when opening.;
the txt and csv are the same file only saved with different extension.
the csv opened in excell migth look like
-1000010
while in fact it is
-1 0 0 0 0 1 0

I hope this helps and not complicates,greetz,

Re: Components and instancing in 1.025

PostPosted: Thu Aug 02, 2012 11:10 am
by smicha
TIG,

You are right - this is not csv, and must be ssv (spaces) or tsv (tabs). While I was experimenting with different separation marks - comas, semicolons - it won't work. So the file I sent you - SSV - is correct.

The last line [0 0 0 1] in 4x4 transformation matrix is redundant (that is what roeland says). That is why one line has 12 elements:
1 0 0 2 0 1 0 3 0 0 1 4 - in input extra spaces every four numbers. SO:
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)
2 3 4 means that an object is translated by 2 meters in X direction, 3 meters in Y (up) amd 4 meters in Z (depth).

Rest zeros are responsible for rotation - I don't know yet.
Here is what Sighman says:

Code: Select all
You REALLY need to brush up on your matrix math if you want to rotate on multiple axis at the same time. Rotating on X then rotating on Y is not the same as rotating on Y and then rotating on X.

Code:
Rotation on X [Mx]        Rotation on Y [My]       Rotation on Z [Mz]

| 1     0      0    0 |   | cos(y) 0 -sin(y) 0 |   |  cos(z) sin(z) 0 0 |
| 0   cos(x) sin(x) 0 |   |   0    1    0    0 |   | -sin(z) cos(z) 0 0 |
| 0  -sin(x) cos(x) 0 |   | sin(y) 0  cos(y) 0 |   |    0      0    1 0 |
| 0     0      0    1 |   |   0    0    0    1 |   |    0      0    0 1 |

If you want to rotate on X then Y [Mx]*[My]

| cos(y)           0       -sin(y)    0 |
| sin(x)*sin(y)  cos(x) sin(x)*cos(y) 0 |
| cos(x)*sin(y) -sin(x) cos(x)*cos(y) 0 |
|       0          0          0       1 |


I'll try your code now and let you know how it works.

Thank you so much for your time and help.