Re: [Bf-committers] Cursor to center of mass

2012-11-21 Thread CoDEmanX
It's pretty easy to handle:

http://www.pasteall.org/37405/python


Am 21.11.2012 04:55, schrieb Brecht Van Lommel:
 Tessfaces includes both triangles and quads, it doesn't triangulate
 entirely, so you'd need to handle the quads still.

 Brecht.

 On Wed, Nov 21, 2012 at 4:30 AM, Ummi Nom ummi...@gmail.com wrote:
 Hi!

 I've written some center of mass calculations in python for closed meshes,
 but there is an issue with using tessfaces in my code; I run mesh.update
 with tessfaces=True but when I loop over mesh.tessfaces there are only 6
 faces in default scene cube so the center of mass is offset.

 It seems to work when the mesh is triangulated
 http://www.pasteall.org/37396/python

 # Code
 import mathutils
 from mathutils import *
 import bpy

 tess_count = 0

 # Handle tri as a tetrahedron with fourth point at origo
 def handleTri(v1, v2, v3):
  global tess_count
  tess_count = tess_count + 1

  temp = (v3-v1).cross(v2-v1)
  nor = temp.normalized()
  area = 0.5*temp.dot(nor)
  vol = area*nor.dot(v1)/3.0
  centroid = (v1+v2+v3)/4.0

  return (centroid, vol)


 for me in bpy.data.meshes:
  me.update(calc_tessface=True)

  sumc= Vector()
  summ = 0


  for f in me.tessfaces:
  v1 = Vector(me.vertices[f.vertices[0]].co)
  v2 = Vector(me.vertices[f.vertices[1]].co)
  v3 = Vector(me.vertices[f.vertices[2]].co)

  centroid, mass = handleTri(v1, v2, v3)
  sumc += centroid * mass
  summ += mass

  print(tess_count)

  print(sumc/summ)
 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers
 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers

___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


Re: [Bf-committers] Cursor to center of mass

2012-11-21 Thread Sergej Reich
Hey Jason,

currently there is a problem with n-gons when chalculating the center of mass.
The issue is that we don't have a good way of calculating centroids for n-gons 
and just use the vertex average, so the calculated origin will drift a little 
when your polygons have many vertices.
I'd prefer to just tirangulate the model and use the triangle centroids but 
after a discussion with Campbell we decided it's not worth allocating a bunch 
of faces just to get a litte more accuracy.

Regards, Sergej.

Am Di, 20. Nov, 2012 um 12:12 ,Jason Wilkins jason.a.wilk...@gmail.com 
schrieb:
Brecht, I figured that was what it did after testing it some, but 
since subdividing a face caused the center to move slightly I had my 
doubts. If it was vertexes I expected a really large move (since 
there were 100 times as many vertexes in my subdivided face than the 
rest of the model), but using faces or tets it should not move at all. 
Did I find a bug? 

On Mon, Nov 19, 2012 at 5:05 PM, Martin Bürbaum 
wrote: 
 Just FYI - I did something similar (Snap Cursor to Centroid) as a script a 
 while back. 
 
 http://projects.blender.org/tracker/index.php?func=detailaid=30299group_id=153atid=467
  
 
 Cheers, 
 Martin 
 
  Original-Nachricht  
 Datum: Mon, 19 Nov 2012 19:00:23 -0300 
 Von: Juan Pablo Bouza 
 An: bf-committers@blender.org 
 Betreff: [Bf-committers] Cursor to center of mass 
 
 
 Hi! The addition of the center of mass option for object origins is 
 really cool! 
 
 Now, there are many times in rigging when you need the center of the 
 object to be at 0 0 0, specially for exporting meshes. So, in these 
 cases, the origin to center of mass option would not be used. 
 Nevertheless, the center of mass options would be really usefull for 
 placing objects such as bones... 
 
 So, I propose to add the center of mass option also in the Cursor 
 snapping menu (shif+S). That would be cursor to center of mass. 
 
 Cheers! 
 ___ 
 Bf-committers mailing list 
 Bf-committers@blender.org 
 http://lists.blender.org/mailman/listinfo/bf-committers 
___ 
Bf-committers mailing list 
Bf-committers@blender.org 
http://lists.blender.org/mailman/listinfo/bf-committers 

___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


Re: [Bf-committers] Cursor to center of mass

2012-11-21 Thread patrick boelens

I can sort of see the reasoning behind that, but I would also argue accuracy 
can be very important. Maybe it'd be worth it to make a high quality operator 
bool in the same vein as the high quality normals in the Solidify modifier?

-Patrick

 Date: Wed, 21 Nov 2012 17:36:19 +0001
 From: sergej.re...@googlemail.com
 To: bf-committers@blender.org
 CC: bf-committers@blender.org
 Subject: Re: [Bf-committers] Cursor to center of mass
 
 Hey Jason,
 
 currently there is a problem with n-gons when chalculating the center of mass.
 The issue is that we don't have a good way of calculating centroids for 
 n-gons and just use the vertex average, so the calculated origin will drift a 
 little when your polygons have many vertices.
 I'd prefer to just tirangulate the model and use the triangle centroids but 
 after a discussion with Campbell we decided it's not worth allocating a bunch 
 of faces just to get a litte more accuracy.
 
 Regards, Sergej.
 
 Am Di, 20. Nov, 2012 um 12:12 ,Jason Wilkins jason.a.wilk...@gmail.com 
 schrieb:
 Brecht, I figured that was what it did after testing it some, but 
 since subdividing a face caused the center to move slightly I had my 
 doubts. If it was vertexes I expected a really large move (since 
 there were 100 times as many vertexes in my subdivided face than the 
 rest of the model), but using faces or tets it should not move at all. 
 Did I find a bug? 
 
 On Mon, Nov 19, 2012 at 5:05 PM, Martin Bürbaum 
 wrote: 
  Just FYI - I did something similar (Snap Cursor to Centroid) as a script 
  a while back. 
  
  http://projects.blender.org/tracker/index.php?func=detailaid=30299group_id=153atid=467
   
  
  Cheers, 
  Martin 
  
   Original-Nachricht  
  Datum: Mon, 19 Nov 2012 19:00:23 -0300 
  Von: Juan Pablo Bouza 
  An: bf-committers@blender.org 
  Betreff: [Bf-committers] Cursor to center of mass 
  
  
  Hi! The addition of the center of mass option for object origins is 
  really cool! 
  
  Now, there are many times in rigging when you need the center of the 
  object to be at 0 0 0, specially for exporting meshes. So, in these 
  cases, the origin to center of mass option would not be used. 
  Nevertheless, the center of mass options would be really usefull for 
  placing objects such as bones... 
  
  So, I propose to add the center of mass option also in the Cursor 
  snapping menu (shif+S). That would be cursor to center of mass. 
  
  Cheers! 
  ___ 
  Bf-committers mailing list 
  Bf-committers@blender.org 
  http://lists.blender.org/mailman/listinfo/bf-committers 
 ___ 
 Bf-committers mailing list 
 Bf-committers@blender.org 
 http://lists.blender.org/mailman/listinfo/bf-committers 
 
 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers
  
___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


Re: [Bf-committers] Cursor to center of mass

2012-11-21 Thread patrick boelens

Oops, I forgot this was about the cursor snapping and had something else in 
mind... My apologies. =)

 From: p_boel...@msn.com
 To: bf-committers@blender.org
 Date: Wed, 21 Nov 2012 20:07:04 +0100
 Subject: Re: [Bf-committers] Cursor to center of mass
 
 
 I can sort of see the reasoning behind that, but I would also argue accuracy 
 can be very important. Maybe it'd be worth it to make a high quality 
 operator bool in the same vein as the high quality normals in the Solidify 
 modifier?
 
 -Patrick
 
  Date: Wed, 21 Nov 2012 17:36:19 +0001
  From: sergej.re...@googlemail.com
  To: bf-committers@blender.org
  CC: bf-committers@blender.org
  Subject: Re: [Bf-committers] Cursor to center of mass
  
  Hey Jason,
  
  currently there is a problem with n-gons when chalculating the center of 
  mass.
  The issue is that we don't have a good way of calculating centroids for 
  n-gons and just use the vertex average, so the calculated origin will drift 
  a little when your polygons have many vertices.
  I'd prefer to just tirangulate the model and use the triangle centroids but 
  after a discussion with Campbell we decided it's not worth allocating a 
  bunch of faces just to get a litte more accuracy.
  
  Regards, Sergej.
  
  Am Di, 20. Nov, 2012 um 12:12 ,Jason Wilkins jason.a.wilk...@gmail.com 
  schrieb:
  Brecht, I figured that was what it did after testing it some, but 
  since subdividing a face caused the center to move slightly I had my 
  doubts. If it was vertexes I expected a really large move (since 
  there were 100 times as many vertexes in my subdivided face than the 
  rest of the model), but using faces or tets it should not move at all. 
  Did I find a bug? 
  
  On Mon, Nov 19, 2012 at 5:05 PM, Martin Bürbaum 
  wrote: 
   Just FYI - I did something similar (Snap Cursor to Centroid) as a 
   script a while back. 
   
   http://projects.blender.org/tracker/index.php?func=detailaid=30299group_id=153atid=467

   
   Cheers, 
   Martin 
   
    Original-Nachricht  
   Datum: Mon, 19 Nov 2012 19:00:23 -0300 
   Von: Juan Pablo Bouza 
   An: bf-committers@blender.org 
   Betreff: [Bf-committers] Cursor to center of mass 
   
   
   Hi! The addition of the center of mass option for object origins is 
   really cool! 
   
   Now, there are many times in rigging when you need the center of the 
   object to be at 0 0 0, specially for exporting meshes. So, in these 
   cases, the origin to center of mass option would not be used. 
   Nevertheless, the center of mass options would be really usefull for 
   placing objects such as bones... 
   
   So, I propose to add the center of mass option also in the Cursor 
   snapping menu (shif+S). That would be cursor to center of mass. 
   
   Cheers! 
   ___ 
   Bf-committers mailing list 
   Bf-committers@blender.org 
   http://lists.blender.org/mailman/listinfo/bf-committers 
  ___ 
  Bf-committers mailing list 
  Bf-committers@blender.org 
  http://lists.blender.org/mailman/listinfo/bf-committers 
  
  ___
  Bf-committers mailing list
  Bf-committers@blender.org
  http://lists.blender.org/mailman/listinfo/bf-committers
 
 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers
  
___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


Re: [Bf-committers] Cursor to center of mass

2012-11-21 Thread Jason Wilkins
Well, the calculation is used first to map the origin of the object
and this discussion was just how to extend that to moving the cursor.

As for it being because of n-gons, I do not think my model contained
n-gons.  What I did was call the subdivide operator 4 times on one end
of the model, which created a bunch of new quads.  Do quads count as
n-gons in this case?

I'll see if I can duplicate it and provide a .blend that narrows this
down if there is a problem.

On Wed, Nov 21, 2012 at 1:08 PM, patrick boelens p_boel...@msn.com wrote:

 Oops, I forgot this was about the cursor snapping and had something else in 
 mind... My apologies. =)

 From: p_boel...@msn.com
 To: bf-committers@blender.org
 Date: Wed, 21 Nov 2012 20:07:04 +0100
 Subject: Re: [Bf-committers] Cursor to center of mass


 I can sort of see the reasoning behind that, but I would also argue accuracy 
 can be very important. Maybe it'd be worth it to make a high quality 
 operator bool in the same vein as the high quality normals in the Solidify 
 modifier?

 -Patrick

  Date: Wed, 21 Nov 2012 17:36:19 +0001
  From: sergej.re...@googlemail.com
  To: bf-committers@blender.org
  CC: bf-committers@blender.org
  Subject: Re: [Bf-committers] Cursor to center of mass
 
  Hey Jason,
 
  currently there is a problem with n-gons when chalculating the center of 
  mass.
  The issue is that we don't have a good way of calculating centroids for 
  n-gons and just use the vertex average, so the calculated origin will 
  drift a little when your polygons have many vertices.
  I'd prefer to just tirangulate the model and use the triangle centroids 
  but after a discussion with Campbell we decided it's not worth allocating 
  a bunch of faces just to get a litte more accuracy.
 
  Regards, Sergej.
 
  Am Di, 20. Nov, 2012 um 12:12 ,Jason Wilkins jason.a.wilk...@gmail.com 
  schrieb:
  Brecht, I figured that was what it did after testing it some, but
  since subdividing a face caused the center to move slightly I had my
  doubts. If it was vertexes I expected a really large move (since
  there were 100 times as many vertexes in my subdivided face than the
  rest of the model), but using faces or tets it should not move at all.
  Did I find a bug?
 
  On Mon, Nov 19, 2012 at 5:05 PM, Martin Bürbaum
  wrote:
   Just FYI - I did something similar (Snap Cursor to Centroid) as a 
   script a while back.
  
   http://projects.blender.org/tracker/index.php?func=detailaid=30299group_id=153atid=467
  
   Cheers,
   Martin
  
    Original-Nachricht 
   Datum: Mon, 19 Nov 2012 19:00:23 -0300
   Von: Juan Pablo Bouza
   An: bf-committers@blender.org
   Betreff: [Bf-committers] Cursor to center of mass
  
  
   Hi! The addition of the center of mass option for object origins is
   really cool!
  
   Now, there are many times in rigging when you need the center of the
   object to be at 0 0 0, specially for exporting meshes. So, in these
   cases, the origin to center of mass option would not be used.
   Nevertheless, the center of mass options would be really usefull for
   placing objects such as bones...
  
   So, I propose to add the center of mass option also in the Cursor
   snapping menu (shif+S). That would be cursor to center of mass.
  
   Cheers!
   ___
   Bf-committers mailing list
   Bf-committers@blender.org
   http://lists.blender.org/mailman/listinfo/bf-committers
  ___
  Bf-committers mailing list
  Bf-committers@blender.org
  http://lists.blender.org/mailman/listinfo/bf-committers
 
  ___
  Bf-committers mailing list
  Bf-committers@blender.org
  http://lists.blender.org/mailman/listinfo/bf-committers

 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers

 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers
___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


Re: [Bf-committers] Cursor to center of mass

2012-11-21 Thread Ummi Nom
Hi!

I finished writing some testing code (only prints out the cm though).
Planar convex/concave n-gon centroids should be correct and for closed
meshes there's the tetrahedron stuff which uses either fake tris from
polys or correct tris from tessfaces. Non-planar polys won't be correct
because of the quick triangulation (v[0], v[i-1], v[i]) and because a
flipped tri (vs polynormal) is always considered to have negative area.

http://www.pasteall.org/37425/python

On Thu, Nov 22, 2012 at 12:20 AM, Jason Wilkins
jason.a.wilk...@gmail.comwrote:

 Well, the calculation is used first to map the origin of the object
 and this discussion was just how to extend that to moving the cursor.

 As for it being because of n-gons, I do not think my model contained
 n-gons.  What I did was call the subdivide operator 4 times on one end
 of the model, which created a bunch of new quads.  Do quads count as
 n-gons in this case?

 I'll see if I can duplicate it and provide a .blend that narrows this
 down if there is a problem.

 On Wed, Nov 21, 2012 at 1:08 PM, patrick boelens p_boel...@msn.com
 wrote:
 
  Oops, I forgot this was about the cursor snapping and had something else
 in mind... My apologies. =)
 
  From: p_boel...@msn.com
  To: bf-committers@blender.org
  Date: Wed, 21 Nov 2012 20:07:04 +0100
  Subject: Re: [Bf-committers] Cursor to center of mass
 
 
  I can sort of see the reasoning behind that, but I would also argue
 accuracy can be very important. Maybe it'd be worth it to make a high
 quality operator bool in the same vein as the high quality normals in
 the Solidify modifier?
 
  -Patrick
 
   Date: Wed, 21 Nov 2012 17:36:19 +0001
   From: sergej.re...@googlemail.com
   To: bf-committers@blender.org
   CC: bf-committers@blender.org
   Subject: Re: [Bf-committers] Cursor to center of mass
  
   Hey Jason,
  
   currently there is a problem with n-gons when chalculating the center
 of mass.
   The issue is that we don't have a good way of calculating centroids
 for n-gons and just use the vertex average, so the calculated origin will
 drift a little when your polygons have many vertices.
   I'd prefer to just tirangulate the model and use the triangle
 centroids but after a discussion with Campbell we decided it's not worth
 allocating a bunch of faces just to get a litte more accuracy.
  
   Regards, Sergej.
  
   Am Di, 20. Nov, 2012 um 12:12 ,Jason Wilkins 
 jason.a.wilk...@gmail.com schrieb:
   Brecht, I figured that was what it did after testing it some, but
   since subdividing a face caused the center to move slightly I had my
   doubts. If it was vertexes I expected a really large move (since
   there were 100 times as many vertexes in my subdivided face than the
   rest of the model), but using faces or tets it should not move at all.
   Did I find a bug?
  
   On Mon, Nov 19, 2012 at 5:05 PM, Martin Bürbaum
   wrote:
Just FYI - I did something similar (Snap Cursor to Centroid) as a
 script a while back.
   
   
 http://projects.blender.org/tracker/index.php?func=detailaid=30299group_id=153atid=467
   
Cheers,
Martin
   
 Original-Nachricht 
Datum: Mon, 19 Nov 2012 19:00:23 -0300
Von: Juan Pablo Bouza
An: bf-committers@blender.org
Betreff: [Bf-committers] Cursor to center of mass
   
   
Hi! The addition of the center of mass option for object origins
 is
really cool!
   
Now, there are many times in rigging when you need the center of
 the
object to be at 0 0 0, specially for exporting meshes. So, in these
cases, the origin to center of mass option would not be used.
Nevertheless, the center of mass options would be really usefull
 for
placing objects such as bones...
   
So, I propose to add the center of mass option also in the Cursor
snapping menu (shif+S). That would be cursor to center of mass.
   
Cheers!
___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers
   ___
   Bf-committers mailing list
   Bf-committers@blender.org
   http://lists.blender.org/mailman/listinfo/bf-committers
  
   ___
   Bf-committers mailing list
   Bf-committers@blender.org
   http://lists.blender.org/mailman/listinfo/bf-committers
 
  ___
  Bf-committers mailing list
  Bf-committers@blender.org
  http://lists.blender.org/mailman/listinfo/bf-committers
 
  ___
  Bf-committers mailing list
  Bf-committers@blender.org
  http://lists.blender.org/mailman/listinfo/bf-committers
 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers

___
Bf-committers mailing list
Bf-committers@blender.org
http

Re: [Bf-committers] Cursor to center of mass

2012-11-21 Thread bjornm...@gmx.net
Did you check against  'non orientable surfaces'?
like
Möbius strip
Klein Bottle
I doubt the algorithm stands with that...
As far as I remember those objects have no defined volume?
As : how would you like  to make a cylinder from a Möbius strip?
You can always create a bounding object  .. like in triangulating the 
circle ..
alas .. it will be getting close enough, which might be sufficient for 
blender, and might be nice to have..

Well if blender refuses to create  such geometry .. bad enough
Mathematica and friends can.

Well I think you should check  the definition of  'closed' and require 
'orientable' and it will work out fine.
so much for that
BM

one more .. your algorithm assumes homogeneous density .. how realistic 
is that ? .. for all cases ?
Is a balloon filled with air the same as the balloon filled with water?
As the mass is on the surface versus the mass is in the volume ?

Am 21.11.2012 04:30, schrieb Ummi Nom:
 Hi!

 I've written some center of mass calculations in python for closed meshes,
 but there is an issue with using tessfaces in my code; I run mesh.update
 with tessfaces=True but when I loop over mesh.tessfaces there are only 6
 faces in default scene cube so the center of mass is offset.

 It seems to work when the mesh is triangulated
 http://www.pasteall.org/37396/python

 # Code
 import mathutils
 from mathutils import *
 import bpy

 tess_count = 0

 # Handle tri as a tetrahedron with fourth point at origo
 def handleTri(v1, v2, v3):
  global tess_count
  tess_count = tess_count + 1

  temp = (v3-v1).cross(v2-v1)
  nor = temp.normalized()
  area = 0.5*temp.dot(nor)
  vol = area*nor.dot(v1)/3.0
  centroid = (v1+v2+v3)/4.0

  return (centroid, vol)


 for me in bpy.data.meshes:
  me.update(calc_tessface=True)

  sumc= Vector()
  summ = 0


  for f in me.tessfaces:
  v1 = Vector(me.vertices[f.vertices[0]].co)
  v2 = Vector(me.vertices[f.vertices[1]].co)
  v3 = Vector(me.vertices[f.vertices[2]].co)

  centroid, mass = handleTri(v1, v2, v3)
  sumc += centroid * mass
  summ += mass

  print(tess_count)

  print(sumc/summ)
 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers


___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


Re: [Bf-committers] Cursor to center of mass

2012-11-21 Thread Tobias Oelgarte
Every algorithm has it's limitations. Computing the center of mass for a 
body that has no volume is a quite useless task and assuming 
inhomogeneous density for a body that is only defined by the surface is 
also questionable. For the average case a closed surface and the 
assumption of homogeneity is already sufficient enough. For anything 
else you could play around with shrinkwrap or something else to create a 
hull that approximates the volume.

Regarding the balloon. It doesn't matter in this case if the mass is 
centred at the surface or inside the volume. The result for the center 
of mass is still the same. It would only matter if you had a balloon 
filled half with water and half air.

Am 22.11.2012 02:46, schrieb bjornm...@gmx.net:
 Did you check against  'non orientable surfaces'?
 like
 Möbius strip
 Klein Bottle
 I doubt the algorithm stands with that...
 As far as I remember those objects have no defined volume?
 As : how would you like  to make a cylinder from a Möbius strip?
 You can always create a bounding object  .. like in triangulating the
 circle ..
 alas .. it will be getting close enough, which might be sufficient for
 blender, and might be nice to have..

 Well if blender refuses to create  such geometry .. bad enough
 Mathematica and friends can.

 Well I think you should check  the definition of  'closed' and require
 'orientable' and it will work out fine.
 so much for that
 BM

 one more .. your algorithm assumes homogeneous density .. how realistic
 is that ? .. for all cases ?
 Is a balloon filled with air the same as the balloon filled with water?
 As the mass is on the surface versus the mass is in the volume ?

 Am 21.11.2012 04:30, schrieb Ummi Nom:
 Hi!

 I've written some center of mass calculations in python for closed meshes,
 but there is an issue with using tessfaces in my code; I run mesh.update
 with tessfaces=True but when I loop over mesh.tessfaces there are only 6
 faces in default scene cube so the center of mass is offset.

 It seems to work when the mesh is triangulated
 http://www.pasteall.org/37396/python

 # Code
 import mathutils
 from mathutils import *
 import bpy

 tess_count = 0

 # Handle tri as a tetrahedron with fourth point at origo
 def handleTri(v1, v2, v3):
   global tess_count
   tess_count = tess_count + 1

   temp = (v3-v1).cross(v2-v1)
   nor = temp.normalized()
   area = 0.5*temp.dot(nor)
   vol = area*nor.dot(v1)/3.0
   centroid = (v1+v2+v3)/4.0

   return (centroid, vol)


 for me in bpy.data.meshes:
   me.update(calc_tessface=True)

   sumc= Vector()
   summ = 0


   for f in me.tessfaces:
   v1 = Vector(me.vertices[f.vertices[0]].co)
   v2 = Vector(me.vertices[f.vertices[1]].co)
   v3 = Vector(me.vertices[f.vertices[2]].co)

   centroid, mass = handleTri(v1, v2, v3)
   sumc += centroid * mass
   summ += mass

   print(tess_count)

   print(sumc/summ)
 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers

 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers


___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


Re: [Bf-committers] Cursor to center of mass

2012-11-21 Thread Ummi Nom
Hi!

I'm aiming a bit lower so I prefer to attack the mechanics of the problem.
Limiting the calculation by actual volume to when it makes sense would be
nice, but detecting overlaps etc. seems overkill.

Here's later code which does it basically two ways, one is the tetrahedron
and the other is polygon centroid.
http://www.pasteall.org/37425/python

On Thu, Nov 22, 2012 at 3:46 AM, bjornm...@gmx.net bjornm...@gmx.netwrote:

 Did you check against  'non orientable surfaces'?
 like
 Möbius strip
 Klein Bottle
 I doubt the algorithm stands with that...
 As far as I remember those objects have no defined volume?
 As : how would you like  to make a cylinder from a Möbius strip?
 You can always create a bounding object  .. like in triangulating the
 circle ..
 alas .. it will be getting close enough, which might be sufficient for
 blender, and might be nice to have..

 Well if blender refuses to create  such geometry .. bad enough
 Mathematica and friends can.

 Well I think you should check  the definition of  'closed' and require
 'orientable' and it will work out fine.
 so much for that
 BM

 one more .. your algorithm assumes homogeneous density .. how realistic
 is that ? .. for all cases ?
 Is a balloon filled with air the same as the balloon filled with water?
 As the mass is on the surface versus the mass is in the volume ?

 Am 21.11.2012 04:30, schrieb Ummi Nom:
  Hi!
 
  I've written some center of mass calculations in python for closed
 meshes,
  but there is an issue with using tessfaces in my code; I run mesh.update
  with tessfaces=True but when I loop over mesh.tessfaces there are only 6
  faces in default scene cube so the center of mass is offset.
 
  It seems to work when the mesh is triangulated
  http://www.pasteall.org/37396/python
 
  # Code
  import mathutils
  from mathutils import *
  import bpy
 
  tess_count = 0
 
  # Handle tri as a tetrahedron with fourth point at origo
  def handleTri(v1, v2, v3):
   global tess_count
   tess_count = tess_count + 1
 
   temp = (v3-v1).cross(v2-v1)
   nor = temp.normalized()
   area = 0.5*temp.dot(nor)
   vol = area*nor.dot(v1)/3.0
   centroid = (v1+v2+v3)/4.0
 
   return (centroid, vol)
 
 
  for me in bpy.data.meshes:
   me.update(calc_tessface=True)
 
   sumc= Vector()
   summ = 0
 
 
   for f in me.tessfaces:
   v1 = Vector(me.vertices[f.vertices[0]].co)
   v2 = Vector(me.vertices[f.vertices[1]].co)
   v3 = Vector(me.vertices[f.vertices[2]].co)
 
   centroid, mass = handleTri(v1, v2, v3)
   sumc += centroid * mass
   summ += mass
 
   print(tess_count)
 
   print(sumc/summ)
  ___
  Bf-committers mailing list
  Bf-committers@blender.org
  http://lists.blender.org/mailman/listinfo/bf-committers
 

 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers

___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


Re: [Bf-committers] Cursor to center of mass

2012-11-21 Thread Sergej Reich
Actually, subdivide creates n-gons in most cases (unless you use it on edge 
rings or the whole mesh), so it's likely to be the problem.

Also here is a quick patch that adds a Cursor to Center of Mass option:
http://www.pasteall.org/37435/diff

Am Mi, 21. Nov, 2012 um 11:20 ,Jason Wilkins jason.a.wilk...@gmail.com 
schrieb:
Well, the calculation is used first to map the origin of the object 
and this discussion was just how to extend that to moving the cursor. 

As for it being because of n-gons, I do not think my model contained 
n-gons. What I did was call the subdivide operator 4 times on one end 
of the model, which created a bunch of new quads. Do quads count as 
n-gons in this case? 

I'll see if I can duplicate it and provide a .blend that narrows this 
down if there is a problem. 

On Wed, Nov 21, 2012 at 1:08 PM, patrick boelens wrote: 
 
 Oops, I forgot this was about the cursor snapping and had something else in 
 mind... My apologies. =) 
 
 From: p_boel...@msn.com 
 To: bf-committers@blender.org 
 Date: Wed, 21 Nov 2012 20:07:04 +0100 
 Subject: Re: [Bf-committers] Cursor to center of mass 
 
 
 I can sort of see the reasoning behind that, but I would also argue accuracy 
 can be very important. Maybe it'd be worth it to make a high quality 
 operator bool in the same vein as the high quality normals in the Solidify 
 modifier? 
 
 -Patrick 
 
  Date: Wed, 21 Nov 2012 17:36:19 +0001 
  From: sergej.re...@googlemail.com 
  To: bf-committers@blender.org 
  CC: bf-committers@blender.org 
  Subject: Re: [Bf-committers] Cursor to center of mass 
  
  Hey Jason, 
  
  currently there is a problem with n-gons when chalculating the center of 
  mass. 
  The issue is that we don't have a good way of calculating centroids for 
  n-gons and just use the vertex average, so the calculated origin will 
  drift a little when your polygons have many vertices. 
  I'd prefer to just tirangulate the model and use the triangle centroids 
  but after a discussion with Campbell we decided it's not worth allocating 
  a bunch of faces just to get a litte more accuracy. 
  
  Regards, Sergej. 
  
  Am Di, 20. Nov, 2012 um 12:12 ,Jason Wilkins schrieb: 
  Brecht, I figured that was what it did after testing it some, but 
  since subdividing a face caused the center to move slightly I had my 
  doubts. If it was vertexes I expected a really large move (since 
  there were 100 times as many vertexes in my subdivided face than the 
  rest of the model), but using faces or tets it should not move at all. 
  Did I find a bug? 
  
  On Mon, Nov 19, 2012 at 5:05 PM, Martin Bürbaum 
  wrote: 
   Just FYI - I did something similar (Snap Cursor to Centroid) as a 
   script a while back. 
   
   http://projects.blender.org/tracker/index.php?func=detailaid=30299group_id=153atid=467

   
   Cheers, 
   Martin 
   
    Original-Nachricht  
   Datum: Mon, 19 Nov 2012 19:00:23 -0300 
   Von: Juan Pablo Bouza 
   An: bf-committers@blender.org 
   Betreff: [Bf-committers] Cursor to center of mass 
   
   
   Hi! The addition of the center of mass option for object origins is 
   really cool! 
   
   Now, there are many times in rigging when you need the center of the 
   object to be at 0 0 0, specially for exporting meshes. So, in these 
   cases, the origin to center of mass option would not be used. 
   Nevertheless, the center of mass options would be really usefull for 
   placing objects such as bones... 
   
   So, I propose to add the center of mass option also in the Cursor 
   snapping menu (shif+S). That would be cursor to center of mass. 
   
   Cheers! 
   ___ 
   Bf-committers mailing list 
   Bf-committers@blender.org 
   http://lists.blender.org/mailman/listinfo/bf-committers 
  ___ 
  Bf-committers mailing list 
  Bf-committers@blender.org 
  http://lists.blender.org/mailman/listinfo/bf-committers 
  
  ___ 
  Bf-committers mailing list 
  Bf-committers@blender.org 
  http://lists.blender.org/mailman/listinfo/bf-committers 
 
 ___ 
 Bf-committers mailing list 
 Bf-committers@blender.org 
 http://lists.blender.org/mailman/listinfo/bf-committers 
 
 ___ 
 Bf-committers mailing list 
 Bf-committers@blender.org 
 http://lists.blender.org/mailman/listinfo/bf-committers 
___ 
Bf-committers mailing list 
Bf-committers@blender.org 
http://lists.blender.org/mailman/listinfo/bf-committers 

___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


[Bf-committers] Cursor to center of mass

2012-11-20 Thread Ummi Nom
Hi!

I've written some center of mass calculations in python for closed meshes,
but there is an issue with using tessfaces in my code; I run mesh.update
with tessfaces=True but when I loop over mesh.tessfaces there are only 6
faces in default scene cube so the center of mass is offset.

It seems to work when the mesh is triangulated
http://www.pasteall.org/37396/python

# Code
import mathutils
from mathutils import *
import bpy

tess_count = 0

# Handle tri as a tetrahedron with fourth point at origo
def handleTri(v1, v2, v3):
global tess_count
tess_count = tess_count + 1

temp = (v3-v1).cross(v2-v1)
nor = temp.normalized()
area = 0.5*temp.dot(nor)
vol = area*nor.dot(v1)/3.0
centroid = (v1+v2+v3)/4.0

return (centroid, vol)


for me in bpy.data.meshes:
me.update(calc_tessface=True)

sumc= Vector()
summ = 0


for f in me.tessfaces:
v1 = Vector(me.vertices[f.vertices[0]].co)
v2 = Vector(me.vertices[f.vertices[1]].co)
v3 = Vector(me.vertices[f.vertices[2]].co)

centroid, mass = handleTri(v1, v2, v3)
sumc += centroid * mass
summ += mass

print(tess_count)

print(sumc/summ)
___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


Re: [Bf-committers] Cursor to center of mass

2012-11-20 Thread Brecht Van Lommel
Tessfaces includes both triangles and quads, it doesn't triangulate
entirely, so you'd need to handle the quads still.

Brecht.

On Wed, Nov 21, 2012 at 4:30 AM, Ummi Nom ummi...@gmail.com wrote:
 Hi!

 I've written some center of mass calculations in python for closed meshes,
 but there is an issue with using tessfaces in my code; I run mesh.update
 with tessfaces=True but when I loop over mesh.tessfaces there are only 6
 faces in default scene cube so the center of mass is offset.

 It seems to work when the mesh is triangulated
 http://www.pasteall.org/37396/python

 # Code
 import mathutils
 from mathutils import *
 import bpy

 tess_count = 0

 # Handle tri as a tetrahedron with fourth point at origo
 def handleTri(v1, v2, v3):
 global tess_count
 tess_count = tess_count + 1

 temp = (v3-v1).cross(v2-v1)
 nor = temp.normalized()
 area = 0.5*temp.dot(nor)
 vol = area*nor.dot(v1)/3.0
 centroid = (v1+v2+v3)/4.0

 return (centroid, vol)


 for me in bpy.data.meshes:
 me.update(calc_tessface=True)

 sumc= Vector()
 summ = 0


 for f in me.tessfaces:
 v1 = Vector(me.vertices[f.vertices[0]].co)
 v2 = Vector(me.vertices[f.vertices[1]].co)
 v3 = Vector(me.vertices[f.vertices[2]].co)

 centroid, mass = handleTri(v1, v2, v3)
 sumc += centroid * mass
 summ += mass

 print(tess_count)

 print(sumc/summ)
 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers
___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


[Bf-committers] Cursor to center of mass

2012-11-19 Thread Juan Pablo Bouza

Hi! The addition of the center of mass option for object origins is really 
cool!

Now, there are many times in rigging when you need the center of the object to 
be at 0 0 0, specially for exporting meshes. So, in these cases, the origin to 
center of mass option would not be used.
Nevertheless, the center of mass options would be really usefull for placing 
objects such as bones...

So, I propose to add the center of mass option also in the Cursor snapping menu 
(shif+S). That would be cursor to center of mass.

Cheers!
  
___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


Re: [Bf-committers] Cursor to center of mass

2012-11-19 Thread Jason Wilkins
I'll ask, since I hope it will save time instead of looking at the
code.  Is the center of mass option actually calculating a center of
mass or is it calculating a centroid?  A centroid would be equivalent
to the center of mass of a set of equally massive points at the
vertexes.  A true center of mass would require some kind of
tetrahedralization and integration over the interior mass of an
object.  That seems quite heavy duty so that is why I'm having doubts
that this feature is named correctly.

On Mon, Nov 19, 2012 at 4:00 PM, Juan Pablo Bouza jpbo...@hotmail.com wrote:

 Hi! The addition of the center of mass option for object origins is really 
 cool!

 Now, there are many times in rigging when you need the center of the object 
 to be at 0 0 0, specially for exporting meshes. So, in these cases, the 
 origin to center of mass option would not be used.
 Nevertheless, the center of mass options would be really usefull for placing 
 objects such as bones...

 So, I propose to add the center of mass option also in the Cursor snapping 
 menu (shif+S). That would be cursor to center of mass.

 Cheers!

 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers
___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


Re: [Bf-committers] Cursor to center of mass

2012-11-19 Thread Jason Wilkins
I did some experiments and it does seem to work quite well, whatever
method is used.  If nobody else wants to look at adding a cursor to
center of mass option for placing the 3D cursor then I'll do it.

On Mon, Nov 19, 2012 at 4:00 PM, Juan Pablo Bouza jpbo...@hotmail.com wrote:

 Hi! The addition of the center of mass option for object origins is really 
 cool!

 Now, there are many times in rigging when you need the center of the object 
 to be at 0 0 0, specially for exporting meshes. So, in these cases, the 
 origin to center of mass option would not be used.
 Nevertheless, the center of mass options would be really usefull for placing 
 objects such as bones...

 So, I propose to add the center of mass option also in the Cursor snapping 
 menu (shif+S). That would be cursor to center of mass.

 Cheers!

 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers
___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


Re: [Bf-committers] Cursor to center of mass

2012-11-19 Thread Brecht Van Lommel
It's based on face areas, so it could be interpreted as the center of
mass of a hollow object.

Brecht.

On Mon, Nov 19, 2012 at 11:37 PM, Jason Wilkins
jason.a.wilk...@gmail.com wrote:
 I did some experiments and it does seem to work quite well, whatever
 method is used.  If nobody else wants to look at adding a cursor to
 center of mass option for placing the 3D cursor then I'll do it.

 On Mon, Nov 19, 2012 at 4:00 PM, Juan Pablo Bouza jpbo...@hotmail.com wrote:

 Hi! The addition of the center of mass option for object origins is really 
 cool!

 Now, there are many times in rigging when you need the center of the object 
 to be at 0 0 0, specially for exporting meshes. So, in these cases, the 
 origin to center of mass option would not be used.
 Nevertheless, the center of mass options would be really usefull for placing 
 objects such as bones...

 So, I propose to add the center of mass option also in the Cursor snapping 
 menu (shif+S). That would be cursor to center of mass.

 Cheers!

 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers
 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers
___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


Re: [Bf-committers] Cursor to center of mass

2012-11-19 Thread Martin Bürbaum
Just FYI - I did something similar (Snap Cursor to Centroid) as a script a 
while back.

http://projects.blender.org/tracker/index.php?func=detailaid=30299group_id=153atid=467

Cheers,
Martin

 Original-Nachricht 
 Datum: Mon, 19 Nov 2012 19:00:23 -0300
 Von: Juan Pablo Bouza jpbo...@hotmail.com
 An: bf-committers@blender.org
 Betreff: [Bf-committers] Cursor to center of mass

 
 Hi! The addition of the center of mass option for object origins is
 really cool!
 
 Now, there are many times in rigging when you need the center of the
 object to be at 0 0 0, specially for exporting meshes. So, in these
 cases, the origin to center of mass option would not be used.
 Nevertheless, the center of mass options would be really usefull for
 placing objects such as bones...
 
 So, I propose to add the center of mass option also in the Cursor
 snapping menu (shif+S). That would be cursor to center of mass.
 
 Cheers!
___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


Re: [Bf-committers] Cursor to center of mass

2012-11-19 Thread Jason Wilkins
Brecht, I figured that was what it did after testing it some, but
since subdividing a face caused the center to move slightly I had my
doubts.  If it was vertexes I expected a really large move (since
there were 100 times as many vertexes in my subdivided face than the
rest of the model), but using faces or tets it should not move at all.
 Did I find a bug?

On Mon, Nov 19, 2012 at 5:05 PM, Martin Bürbaum
martin.buerb...@gmx.at wrote:
 Just FYI - I did something similar (Snap Cursor to Centroid) as a script a 
 while back.

 http://projects.blender.org/tracker/index.php?func=detailaid=30299group_id=153atid=467

 Cheers,
 Martin

  Original-Nachricht 
 Datum: Mon, 19 Nov 2012 19:00:23 -0300
 Von: Juan Pablo Bouza jpbo...@hotmail.com
 An: bf-committers@blender.org
 Betreff: [Bf-committers] Cursor to center of mass


 Hi! The addition of the center of mass option for object origins is
 really cool!

 Now, there are many times in rigging when you need the center of the
 object to be at 0 0 0, specially for exporting meshes. So, in these
 cases, the origin to center of mass option would not be used.
 Nevertheless, the center of mass options would be really usefull for
 placing objects such as bones...

 So, I propose to add the center of mass option also in the Cursor
 snapping menu (shif+S). That would be cursor to center of mass.

 Cheers!
 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers
___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers


Re: [Bf-committers] Cursor to center of mass

2012-11-19 Thread Juan Pablo Bouza

Thanks for looking into this guys! You're the best :D



 Date: Mon, 19 Nov 2012 17:12:00 -0600
 From: jason.a.wilk...@gmail.com
 To: bf-committers@blender.org
 Subject: Re: [Bf-committers] Cursor to center of mass
 
 Brecht, I figured that was what it did after testing it some, but
 since subdividing a face caused the center to move slightly I had my
 doubts.  If it was vertexes I expected a really large move (since
 there were 100 times as many vertexes in my subdivided face than the
 rest of the model), but using faces or tets it should not move at all.
  Did I find a bug?
 
 On Mon, Nov 19, 2012 at 5:05 PM, Martin Bürbaum
 martin.buerb...@gmx.at wrote:
  Just FYI - I did something similar (Snap Cursor to Centroid) as a script 
  a while back.
 
  http://projects.blender.org/tracker/index.php?func=detailaid=30299group_id=153atid=467
 
  Cheers,
  Martin
 
   Original-Nachricht 
  Datum: Mon, 19 Nov 2012 19:00:23 -0300
  Von: Juan Pablo Bouza jpbo...@hotmail.com
  An: bf-committers@blender.org
  Betreff: [Bf-committers] Cursor to center of mass
 
 
  Hi! The addition of the center of mass option for object origins is
  really cool!
 
  Now, there are many times in rigging when you need the center of the
  object to be at 0 0 0, specially for exporting meshes. So, in these
  cases, the origin to center of mass option would not be used.
  Nevertheless, the center of mass options would be really usefull for
  placing objects such as bones...
 
  So, I propose to add the center of mass option also in the Cursor
  snapping menu (shif+S). That would be cursor to center of mass.
 
  Cheers!
  ___
  Bf-committers mailing list
  Bf-committers@blender.org
  http://lists.blender.org/mailman/listinfo/bf-committers
 ___
 Bf-committers mailing list
 Bf-committers@blender.org
 http://lists.blender.org/mailman/listinfo/bf-committers
  
___
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers