Transform by vectors and Hash.
-
Hi. Coming from this topic:
http://sketchucation.com/forums/viewtopic.php?f=180&t=51263
(BTW moderators, regarding that post. Since it was started regarding information about Group name = make_uniq. I would not mind deleting those last posts or perhaps move them here since discussion was headed towards solving a different unrelated problem?)
Ok. to question.
Wondering for best stategy using transform_by_vectors.
I'm inside a for-loop adding groups to faces. The groups are all appended in a parentgroup.
I have vertice transformations to apply to entities inside the groups.Recommendations says this should be performed in 1 big go, preferably after looping.
Transform_by_vectors takes 2 arrays as arguments, ok. So I tried appending those while looping to 2 arrays verts and vecs.
The problem is that if I don't loop the groups individually I get splats?
I.e this do not work. parentgroup.entities.transform_by_vectors( verts, vecs )
(Remember parentgroup holds all the groups with contains the vertices.)So what is working is storing the groups, vertices and vectors in a Hash like so:
Hash{group => [vertices, [vectors]}] . Note there can be many key, value pairs here.But I have to loop the groups again.
for k,v in hash k.entities.transform_by_vectors( v[0], v[1] ) # end
That works but I get very little performance gain compared to transforming inside the first big loop.
I'll keep working on it, but if anyone has any tip I wouldent mind getting a push in the right direction.
I have a feeling that what I'm trying to do might not be practically possible the Ruby way.BTW. I have a counter inside the big loop. It starts counting fast and slows down and if many loops it stops counting and webdialog X(closebutton) becomes red. Signs of reccursion or just plain Sketchup freeze?
-
hi may be of use... maybe not.
whenI made a ruby to make the entire mac font library as 3d text in a row, it was painfully slow, but by breaking it into chunks solved that problem, dan helped me with the code, the original is in the same post
http://sketchucation.com/forums/viewtopic.php?f=180&t=48761&start=30#p440763john
-
Very interesting Driven.
I have missed that topic completely during my searchs.
It's bedtime early today, so I have a closer peak tomorrow.
Thanks for the link. -
Had a peek inside that topic and while it's very interesting reading I'm uncertain it will help me in this case?
Refering to group make uniq! VS group name. It seems Group.name is a tad quicker.(horray!)
BUT, creating many new groups is very costly. In fact it's nearly half of the calculationtime for my script at the moment. Adding entities are of course expensive, but the difference between using instances and new groups is enourmous.(A longshot: There is no way to do Matrice calculations that affect tapering in Sketchup ?
I've gotten some shearing results when playing with the Matrix, but that's about it..)Biggest lag comes from transformation of vertices. Trying to bundle them do speed up things, but still far from satisfactory, and I doubt I'll ever get near any sufficient workable results..
So problem A is since making groups uniq and transforming by vectors are all SU API methods I can not get any benefit from a C-extension I persume? (If I ever go that route..)
Anyway I think I've made a big rookie misstake when preparing and gathering information for doing all in a big loop. But then again I don't if know slicing the code up will prevent from problem A? Confused right now
See if I can split up the code a little. Any suggestions would be appreciated.
-
You can only transform in one Entities object at a time - you cannot combine transformations in multiple Entities objects.
-
Ah ok, you are refering to tapering, right ?
I sent you PM.
-
@jolran said:
There is no way to do Matrice calculations that affect tapering in Sketchup ?
I don't know the API so well, but mathematically, the matrices would only be able to do what are known as "affine transformations", which have the property that lines which start out parallel with each other always remain parallel - so tapering would not be possible.
-
@unknownuser said:
mathematically, the matrices would only be able to do what are known as "affine transformations"
That IS what I wondered. Bummer
Whats the term for tapering? I've seen it being called "projective scaling". That is what I wanted to do to component instances anyway. Scaling one instance doesent affect the other and so on...
-
@jolran said:
Whats the term for tapering? I've seen it being called "projective scaling". That is what I wanted to do to component instances anyway. Scaling one instance doesent affect the other and so on...
You CAN do this.. BUT each instance must be unique.
Imagine a "Box" component.
Insert two instances a few feet from one another.
If you edit one instance, you will affect the other because they both share the same definition, that "owns" the entities collection.
But select one of them, right-click and choose "Make unique" and it has it's own definition.
Now.. double-click it to enter it's edit-mode. Select the top face, and then choose the ScaleTool.
Hold down the CTRL key and click-drag one of the corner handles to taper the top face (about the center.) -
Yeah Dan thanks, sort of doing that in my code already..
But what i wished for was tapering one instance and it doesent affect the other and so on.
Now that apparently can't be done with current API, otherwise Fredoscale taper-mode probably wouldent exist.
Don't know if that sort of thing could be added to the API anyway since Sketchup is a surface modeler. Maybe need nurbs for this kind of behaviour ?
Anyway getting OT on my own topic..
-
@jolran said:
Don't know if that sort of thing could be added to the API anyway since Sketchup is a surface modeler. Maybe need nurbs for this kind of behaviour ?
NO not now, because the vertice positions are part of the definition, and not part of the individual instance(s).
An interesting idea.
-
@unknownuser said:
NO not now, because the vertice positions are part of the definition, and not part of the individual instance(s).
Thanks for answering Dan.
It could be an useful addition to the API, IMO.What confuses me is that we are moving the vertices when scaling the instance(s) using Sketchup normal scaling behavior. So why would it be different if doing a tapering ?
I know the calculations for tapering is much more complex, but...
Maybe there is need for some symmetry calculation I havent thought about.
Advertisement