• Login
sketchucation logo sketchucation
  • Login
๐Ÿค‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

ComponentInstance global transformation problem

Scheduled Pinned Locked Moved Developers' Forum
7 Posts 2 Posters 350 Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    fuzzybro
    last edited by 20 Sept 2013, 22:16

    Hi all,

    I have a simple situation when I have 2 ComponentInstances selected in the editor and I'm making a new Component out of them. The problem is that I'm unable to calculate a proper global transformation for each instance in the definition.

    Say, I had two instances of a one definition:

    model.entities -> [inst1, inst2]
    

    Then I select them and make a new component, so model looks like this:

    model.entities -> [inst3]
    inst3.definition.entities -> [inst1, inst2]
    

    Then i simply need to go through the hierarchy to get global transformations:

    glob1 = inst3.transformation * inst1.transformation
    glob2 = inst3.transformation * inst2.transformation
    

    This works fine when I'm making a new component, deselect it and go through all of the entities. But everything goes wrong when the component is being active. I know that SketchUp has an edit_transformation space for all the model.active_entities but it is inst3 that is active. Inst3 is placed in the model root and the edit_transformation is an identity matrix. So I have identical inst3 transformations for both selected and deselected cases but inst1 and inst2 transformations are different in case of inst3 being selected and deselected. How do I get global transformations for inst1-2?

    [OctaneRender for SketchUp Overview and Demo Version(http://sketchucation.com/click.php?url)]

    Latest updates, tutorials and artwork
    facebook.com/octane4sketchup

    1 Reply Last reply Reply Quote 0
    • T Offline
      tt_su
      last edited by 22 Sept 2013, 18:19

      What code are you using to get the transformation of inst1 and 2 when inst3 is open?

      I'm not sure if I fully understand your setup and exactly what code you are using at the given time.

      1 Reply Last reply Reply Quote 0
      • T Offline
        tt_su
        last edited by 22 Sept 2013, 18:23

        @fuzzybro said:

        So I have identical inst3 transformations for both selected and deselected cases but inst1 and inst2 transformations are different in case of inst3 being selected and deselected.

        You say selected, but do you mean open?
        Selection doesn't affect transformation at all.

        1 Reply Last reply Reply Quote 0
        • F Offline
          fuzzybro
          last edited by 23 Sept 2013, 09:42

          @tt_su said:

          @fuzzybro said:

          So I have identical inst3 transformations for both selected and deselected cases but inst1 and inst2 transformations are different in case of inst3 being selected and deselected.

          You say selected, but do you mean open?
          Selection doesn't affect transformation at all.

          Hi Thomas,

          This instance isn't opened, at least I don't open it myself but maybe SketchUp performs some sort of similar operation while creating a new Definition, Instance and placing components into it.

          I'm using following code to get transformations of scene entities after new ComponentDefinition and Instance was created:

          
              @model = Sketchup.active_model
              # close all active edit sessions to prevent crashes
              while (!@model.active_path.nil?)
                @model.close_active
              end
              @model.selection.clear
                
              # recursive function to go through all of the instances
              export_component(@model.entities)
          
              ... 
          
              def export_component(entities)
          
                if entities.class == Sketchup;;ComponentInstance
                  return if entities.hidden? or !entities.layer.visible?
                  # remember entityID, get instance local transformation and use it somehow
                  entity_list = definition.entities 
                else
                  entity_list = entities
                end
          
                entity_list.each { |entity| 
                  if entity.layer.visible?
                    export_component(entity) if !entity.hidden?          
                  end
                }
              end
          
          

          This way I'm getting all the local transformations and the hierarchy of the model. Then I just have to go through the hierarchy and accumulate local matrices to get the global matrix as I described earlier.

          But when I try to track changes via EntitiesObserver on create new component event I get 2 calls of onElementRemoved which removes instances inst1 and inst2, 1 call of onElementAdded, which creates inst3 and 2 calls of an onElementModified - one for ComponentIstance which has been added and one for ComponentDefinition for this instance. Oddly enough, I don't get any events for inst1 and inst2 as they have been removed before creating new component but they are present in new ComponenDefinition.entities. In onElementAdded I'm getting the transformation of a newly created inst3 and getting transformations of child Instances inst1 and inst2 which are present in the definition of inst3. At this stage I'm getting completely different transformations for inst1 and inst2 which results in a wrong global transformation when I' doing the multiplication.

          I think than at onElementAdded call stage inst1 and inst2 might have not changed their matrices from model root space to inst3 local space, I'll check it in couple of minutes and report you in that.

          But the other question is why I'm failing to receive events that removed instances inst1 and inst2 have been added or modified? I'm adding an EntityObserver to a newly created definition of an inst3 but don't receive any messages. I guess that I could use these events to get a proper matrices of a newly created inst1 and inst2 in the inst3 space.

          [OctaneRender for SketchUp Overview and Demo Version(http://sketchucation.com/click.php?url)]

          Latest updates, tutorials and artwork
          facebook.com/octane4sketchup

          1 Reply Last reply Reply Quote 0
          • F Offline
            fuzzybro
            last edited by 23 Sept 2013, 10:29

            hmmm.. something goes wrong, I can reproduce this behaviour only in half of the runs.. please, never mind this message till I'll figure out the problem.

            Cheers,
            V.

            [OctaneRender for SketchUp Overview and Demo Version(http://sketchucation.com/click.php?url)]

            Latest updates, tutorials and artwork
            facebook.com/octane4sketchup

            1 Reply Last reply Reply Quote 0
            • F Offline
              fuzzybro
              last edited by 23 Sept 2013, 13:28

              False alarm - it was a bug in my code. Sorry about that, everything works like a charm.

              [OctaneRender for SketchUp Overview and Demo Version(http://sketchucation.com/click.php?url)]

              Latest updates, tutorials and artwork
              facebook.com/octane4sketchup

              1 Reply Last reply Reply Quote 0
              • T Offline
                tt_su
                last edited by 23 Sept 2013, 18:05

                ๐Ÿ‘ ๐Ÿ‘

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                1 / 1
                • First post
                  1/7
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement