Position_material problem
-
Hi,
I'm using some images as textures for faces in the model. To position textures correctly for each face, I calculate position of texture and add texture with 'position_material' method.
While testing plugin on various examples, I've encountered next problem, which I don't have idea how to solve.Assume that 'face' is Face object on which we apply new texture, and that it is inside some group.
Example code:materials = Sketchup.active_model.materials material = materials['material_name'] face.position_material(material,[[237.274, 715.334, 199.096], [0, 0, 0], [467.052, 715.334, 391.903], [1, 0, 0]],true)
If I'm outside of the group where 'face' entity is previous code gives texture 'material_name' positioned correctly on the face.
If I'm inside of the group where 'face' entity is, previous code positions 'material_name' completely wrong.
In both cases I use exactly the same points coordinates for material positioning.Note that vice versa problem happens also: if I set coordinates so positioning is correct while group is opened, when I close the group and try to position material it is wrong.
Why this is important for my plugin: once materials are imported their coordinates are saved as attributes for each face. I have option in plugin to toggle on/off these materials (and show face default material instead).
When I should toggle on materials - I use get_attribute to get coordinates and then position materials on faces.In case that different groups are opened in the moment of import and later during toggling - I get wrong positioning of textures.
It seems like this coordinates are treated as local for the group or something like that, and my assumption was that these are coordinates in SketchUp coordinate system.
Any ideas why this happens and how to solve the problem.
Thanks in advance,
Marija -
When you open a group/component in SketchUp all coordinates are transformed to world coordinates. Use
Model.edit_transform
(https://developers.google.com/sketchup/docs/ourdoc/model#edit_transform) to calculate local co-ordinates for your 3d points. -
Thanks for fast answer.
I've tried straightforward using of this function, but doesn't give expected results.
I suppose solution would be more complex like:
*edit_transform before materials are positioned for the first time
*then when toggling materials on/off again some edit_transform or maybe inverse etc.I'll experiment on this, and send some info about my progress in a few days.
Thanks again,
Marija -
You need to apply the reverse transformation of
model.edit_transform
to get the local coordinates. -
Hi,
After few days of trying to make my coordinates calculation work correct, I still have no good solution.
And I've come to problem how to calculate absolute point coordinates, when I have only relative ones. And problem is with various cases when face is in group, or in nested group or outside of group etc...
Is there some plugin which can from relative coordinates (based on currently opened groups in model), calculate absolute coordinates in SU coordinate system.
For example to get group origin for various cases I have a face in a group I get group origin as:
group = face.parent.instances[0] origin = group.transformation.origin
This gives me various results depending whether group is opened or not:
*group opened - origin is [0,0,0]
*group closed, but parent group opened - it gives me good absolute values for group origin
*group closed and parent group closed - origin is [0,0,0]
*group closed, parent closed, some other group opened - origin is [0,0,0]How to get group origin coordinates in cases when I get [0,0,0]?
In first case model.edit_transform gives me values needed.
But in other two cases - since edit_transform is not solution.Is there some standard way to get absolute coordinates - no meter which group is opened?
Any idea is welcome,
Marija -
@maricanis said:
Is there some standard way to get absolute coordinates - no meter which group is opened?
As mentioned before:
model.edit_transform
https://developers.google.com/sketchup/docs/ourdoc/model#edit_transform@unknownuser said:
Returns the transformation of the current component edit session. If a user has double-clicked to edit a component's geometry, this will return the transformation of that component, relative to its parent's origin. This allows one to correctly calculate "local" transformations of a given entity regardless of whether the user is in edit mode.
I do not know why you don't get correct results - hard to guess. If you post a sample code snippet...
-
Hi Thom,
Here is example and results (I'm obviously doing something wrong, but not sure where the problem is).
In model I have 2 groups:
group1 - consisting of 2 subgroups, where one subgroup contains face we analyze in example
group2 - consisting of some object.Here is the code, to get the face I go through hierarchy - but every time it is the same face
face = Sketchup.active_model.entities[1].entities[1].entities[14] p1 = face.outer_loop.vertices[0].position t1 =Sketchup.active_model.edit_transform p1_trans_inv = p1.transform(t1.inverse()) puts "P1 coordinates [#{p1.to_a.join(',')}]" puts "Edit_transform [#{t1.to_a.join(',')}]" puts "Edit_transform_inverse [#{t1.inverse.to_a.join(',')}]" puts "P1_transform_inverse [#{p1_trans_inv.to_a.join(',')}]"
Absolute P1 coordinates in SU coordinate system are:[-393.700787401575,196.850393700787,0.0]
I call this small script for various cases of opened groups inside model and here are results:
*opened group where face is
P1 coordinates [-393.700787401575,196.850393700787,0.0]
Edit_transform [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,-548.031496062992,196.850393700787,0.0,1.0]
Edit_transform_inverse [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,548.031496062992,-196.850393700787,-0.0,1.0]
P1_transform_inverse [154.330708661417,0.0,0.0]*closed group with face, opened parent group
P1 coordinates [154.330708661417,0.0,0.0]
Edit_transform [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,-548.031496062992,196.850393700787,0.0,1.0]
Edit_transform_inverse [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,548.031496062992,-196.850393700787,-0.0,1.0]
P1_transform_inverse [702.362204724409,-196.850393700787,0.0]*closed group with face, opened parent group, opened other group in the parent
P1 coordinates [154.330708661417,0.0,0.0]
Edit_transform [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,-367.646959030915,310.128373863173,80.3149606299213,1.0]
Edit_transform_inverse [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,367.646959030915,-310.128373863173,-80.3149606299213,1.0]
P1_transform_inverse [521.977667692332,-310.128373863173,-80.3149606299213]*closed group, closed parent group, opened some other group
P1 coordinates [154.330708661417,0.0,0.0]
Edit_transform [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,-464.698354923942,49.8468801242114,-1.13686837721616e-013,1.0]
Edit_transform_inverse [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,464.698354923942,-49.8468801242114,1.13686837721616e-013,1.0]
P1_transform_inverse [619.029063585359,-49.8468801242114,1.13686837721616e-013]*closed all groups
P1 coordinates [154.330708661417,0.0,0.0]
Edit_transform [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
Edit_transform_inverse [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
P1_transform_inverse [154.330708661417,0.0,0.0]As you can see using inverse edit_transform gives each time different results for 'P1_transform_inverse', depending which group is opened - and my goal is to get in each case the same results (since these should be absolute coordinates)
Also notice- that when group with face is opened- we get absolute coordinates (and not relative to the group origin), while in all other cases we get relative coordinates for p1.
So as in previous mail my question is how to get correct absolute coordinates for all other cases (when group with face is closed, and some or no other groups are opened)?
Thanks for patience,
Marija
Advertisement