总结组件、Google Sketchup 中材料的区域

发布于 2024-09-03 04:00:13 字数 253 浏览 10 评论 0原文

我正在制作一个插件来总结草图中所有材料的面积。 我已经成功地获得了所有的面孔等,但现在组件进入了图片。

我使用术语“单级或多级组件”,因为我不知道有任何更好的方法来解释组件内部存在组件的情况等等。

我注意到有些组件的 i 级别也不仅仅是 1 级。因此,如果您进入一个组件内部,该组件中可能嵌入了也具有材料的组件。所以我想要的是总结特定组件的所有材料,并获取组件内的所有“递归”材料(如果有)。

那么,如何计算组件(单层或多层)内所有材料的面积?

I am making a plugin to sum up the area of all the material in a Sketch.
I have succeeded in getting all the faces and such, but now the Components come into the picture.

Im using the term single or multi leveled component as i dont know any better way to explain the occurence of having a component inside an component and so on.

I have noticed that some components also have more to i than just 1 level. So if you go inside one component there may be components embedded inside this component that also have materials. So what i want is to sum up all of the material of a specific component and get all the "recursive" materials, if any, inside the component.

So, how do I count the area of all the material inside an component(single or multileveled)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

安静被遗忘 2024-09-10 04:00:13

这就是我要做的,假设您循环遍历所有实体并检查实体的类型。

if entity.is_a? Sketchup::ComponentInstance
  entity.definition.entities.each {|ent|
    if ent.is_a? Sketchup::Face
      #here do what you have to do to add area to your total
    end
  }
end

您可以对群组执行相同的操作:

if entity.is_a? Sketchup::Group
  entity.entities.each {|ent|
    if ent.is_a? Sketchup::Face
      #here do what you have to do to add area to your total
    end
  }
end

希望有帮助
拉迪斯拉夫

Here is what I would do, let's suppose that you loop through all entities and check for type of entity.

if entity.is_a? Sketchup::ComponentInstance
  entity.definition.entities.each {|ent|
    if ent.is_a? Sketchup::Face
      #here do what you have to do to add area to your total
    end
  }
end

You can do the same with a Group with:

if entity.is_a? Sketchup::Group
  entity.entities.each {|ent|
    if ent.is_a? Sketchup::Face
      #here do what you have to do to add area to your total
    end
  }
end

Hope it helps
Ladislav

云雾 2024-09-10 04:00:13

拉迪斯拉夫的例子并没有深入到所有层面。

为此,您需要一个递归方法:

def sum_area( material, entities, tr = Geom::Transformation.new )
  area = 0.0
  for entity in entities
    if entity.is_a?( Sketchup::Group )
      area += sum_area( material, entity.entities, tr * entity.transformation )
    elsif entity.is_a?( Sketchup::ComponentInstance )
      area += sum_area( material, entity.definition.entities, tr * entity.transformation )
    elsif entity.is_a?( Sketchup::Face ) && entity.material == material
      # (!) The area returned is the unscaled area of the definition.
      #     Use the combined transformation to calculate the correct area.
      #     (Sorry, I don't remember from the top of my head how one does that.)
      #
      # (!) Also not that this only takes into account materials on the front
      #     of faces. You must decide if you want to take into account the back
      #     size as well.
      area += entity.area
    end
  end
  area
end

Ladislav's example doesn't dig into all the levels.

For that you need a recursive method:

def sum_area( material, entities, tr = Geom::Transformation.new )
  area = 0.0
  for entity in entities
    if entity.is_a?( Sketchup::Group )
      area += sum_area( material, entity.entities, tr * entity.transformation )
    elsif entity.is_a?( Sketchup::ComponentInstance )
      area += sum_area( material, entity.definition.entities, tr * entity.transformation )
    elsif entity.is_a?( Sketchup::Face ) && entity.material == material
      # (!) The area returned is the unscaled area of the definition.
      #     Use the combined transformation to calculate the correct area.
      #     (Sorry, I don't remember from the top of my head how one does that.)
      #
      # (!) Also not that this only takes into account materials on the front
      #     of faces. You must decide if you want to take into account the back
      #     size as well.
      area += entity.area
    end
  end
  area
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文