Measure script (Blender 2.5x and newer)

Great work with the script pontiac! I was curious how the new version was coming? I’m going to be teaching a group of Architects in January and would love to make use of the new version.

You are in luck, I had a free day today and just finished the last bit of testing.
The most recent version (Version 0.8.2) is now uploaded to the blender SVN repo (and my git repo as well).

  • It supports the edge length measurement in object-mode and edit-mode.

  • Also the “Update selection” button is now on the very top of the panel - mainly so it doesn’t move around when activating/deactivating things.

Thanks! Seems to work perfect.

Works good…

it still would be nice to have a real tape measure inside the scene…

Great work pontiac! Works very nice!

Have you seen this article: “Polyhedral Mass Properties”?

In the end of article have a pseudo code to measure the mass (volume), and center of mass. I implemented this in Blender. However only works to triagular mesh, maybe you have a idea how change this.

cm = [0.,0.,0.]

def calculateVolume(mymesh):				# volume calculation
	triangulateNMesh(mymesh)
	mult = [1./6., 1./24., 1./24., 1./24., 1./60., 1./60., 1./60., 1./120., 1./120., 1./120.]
	intg = [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]
	fg = [0., 0., 0., 0., 0., 0.]
	vtot = 0.
	for f in mymesh.faces:
		#get vertices of triangle
		fzn = f.normal[2]
		x0 = f.v[0].co[0]
		y0 = f.v[0].co[1]
		z0 = f.v[0].co[2]
		x1 = f.v[1].co[0]
		y1 = f.v[1].co[1]
		z1 = f.v[1].co[2]
		x2 = f.v[2].co[0]
		y2 = f.v[2].co[1]
		z2 = f.v[2].co[2]
		# get edges and cross product of edges		
		a1 = x1 - x0 
		b1 = y1 - y0 
		c1 = z1 - z0
		a2 = x2 - x0
		b2 = y2 - y0
		c2 = z2 - z0
		d0 = b1 * c2 - b2 * c1
		d1 = a2 * c1 - a1 * c2
		d2 = a1 * b2 - a2 * b1
		#compute integral terms
		subexpr(x0, x1, x2, fg);
		f1x = fg[0]
		f2x = fg[1]
		f3x = fg[2]
		g0x = fg[3]
		g1x = fg[4]
		g2x = fg[5]
		subexpr(y0, y1, y2, fg);
		f1y = fg[0]
		f2y = fg[1]
		f3y = fg[2]
		g0y = fg[3]
		g1y = fg[4]
		g2y = fg[5]
		subexpr(z0, z1, z2, fg);
		f1z = fg[0]
		f2z = fg[1]
		f3z = fg[2]
		g0z = fg[3]
		g1z = fg[4]
		g2z = fg[5]
		#update integrals
		intg[0] += d0 * f1x
		intg[1] += d0 * f2x
		intg[2] += d1 * f2y
		intg[3] += d2 * f2z
		intg[4] += d0 * f3x
		intg[5] += d1 * f3y
		intg[6] += d2 * f3z
		intg[7] += d0*(y0 * g0x + y1 * g1x + y2 * g2x)
		intg[8] += d1*(z0 * g0y + z1 * g1y + z2 * g2y)
		intg[9] += d2*(x0 * g0z + x1 * g1z + x2 * g2z)
	for i in range(0,9):
		intg[i] *= mult[i]
	vtot = intg[0]
	cm[0] = (intg[1] / vtot)
	cm[1] = (intg[2] / vtot)
	cm[2] = (intg[3] / vtot)
	return vtot

The most recent version (Version 0.8.4) is now uploaded to the blender SVN repo (and my git repo as well).

  • Please be aware that these changes are NOT in Blender 2.62!
  • It now displays Units in the 3D view as well (Patch by Alessandro Sala)
  • Some minor cleanups and fixes (e.g. order of matrix indices)

I’m currently working on getting the issue with heavy CPU load on bigger meshes solved (not easy without making calulaction-updates completely manual).
If anybody wants to test the development version of this feel free to contact me.

Sorry for the late answer - Thank you for the information & code. I’ll have to get a more detailed look at this to see how easy it is to implement in the current add-on.

But I’m curious: Is there really a need for the center of mass for Blender users?
And if so, wouldn’t this make more sense as an actual tool (e.g. move 3D cursor to the center of mass)?

Cheers,
Martin

Hi Martin,

I don’t know if is useless for others users, but I use this value, center of mass, as references on my work.
But, please dont waste your time, you made a really nice job :slight_smile:

This is one of my articles: http://iopscience.iop.org/0031-9155/56/13/002

Now, I’m working on a newborn,

Cheers,
Vagner

The only reason I asked was because I found it strange to only display the CoM.
I created and uploaded a separate add-on that snaps the 3D cursor to the CoM (actually to the centroid [1]), so you can work with it.

It is available in the “Snap” menu [Shift][S] in the 3D View.

You can download the first draft here:
http://projects.blender.org/tracker/index.php?func=detail&aid=30299&group_id=153&atid=467

Feedback is welcome - if possible in the tracker. I think I’ll create a new thread for this add-on if it works as expected :slight_smile:

[1] The centroid (also called the geometric center) is equal to the CoM when the density is uniform.

Congrats! :wink:

Cheers,
Martin

The most recent version (Version 0.8.9) is now uploaded to the blender SVN repo (and my git repo as well as some point).

  • More efficient calculation of data.
    So the add-on should not eat CPU when idle (except for drawing the 3D lines when activated).
    BUT: It still hogs the CPU when doing simple translating/scaling/rotating. Not much I can do about that :-/
  • Fixed normal calculation for global mode.
  • Calculate surface area & normals for n-gons.
  • Lots of internal changes + Updated for changes in API
  • Cleaner unregister of the add-on (Some is still TODO)

vfcassola: Did you have a chance to test the CoM script?

sorry do you have a specific link to download this

or is it in first post may be ?

thanks

You can download it here fresh from the Blender SVN repository (the link is also in the 1. post):
http://projects.blender.org/scm/viewvc.php/checkout/trunk/py/scripts/addons/space_view3d_panel_measure.py?root=bf-extensions

BUT: You need a very recent version of Blender (e.g. from GraphicAll) to run it. Some of the mesh API changed recently.

you mean updated for Bmesh API!

just got latest release SVN

thanks

Thanks Pontiac for all your coding. Just found the Math script and will be showing my CNC Machinist as he’s looking to do surface points for his CNC to do elliptical shapes on a project.
The Measure addon looks really awesome too.
Just got a new computer with new graphics card and 32GB ram if you need some testing done, I’ll be glad to do it.

Cheers

I have been using your script for many purposes, mainly in arch. drawing when possible etc… However it has become evident to me that when I set blender units to imperial that the measure panel gives me read-outs in yards rather than feet-inches. There is no dimensioning process in the real world which uses yards as units other than american football that I know of. Could you either point out to me where and/or how to modify the script or modify it yourself so it reads out feet and inches in the imperial settings? I don’t really care what it does in the SI settings. my email is [email protected]

Hi Reidh, I’m sorry for the late answer.

The display in the panel uses the blender-internal unit conversion to display the units. Not much I can do there personally.

The units in the 3D View are (/have to be) calculated in the “getUnitsInfo()” and “convertDistance” functions (by Alessandro Sala) in the space_view3d_panel_measure.py script right now. In theory you can modify the code to get better results there, but I didn’t look into the details since it’s not my own code :-).

But to be honest, I’d rather see an option like this in Blender first before updating the script.
As you describe it it would make sense to have an “architecture” option or something like that in the Units panel of the Scene.

Hello pontiac and Reidh,
I had a look and it seems that, at least from v2.64, Blender does not display yards anymore but uses feet instead, so I updated the “getUnitsInfo()” and “convertDistance” functions accordingly.

In the attached file you can find the updated functions: you can simply replace the original functions with the new ones.

Cheers,
Alessandro

Attachments

display_units.zip (864 Bytes)

Really? I must’ve check a bit too early then :slight_smile:

Thank you for the updated code.
I’ll test and integrate it as soon as I have access to a machine that can build Blender again.

Cheers,
Martin

Hi Salex,

I just tested the patch and noticed something strange:

  • Sometimes the script displays two ’ (instead of ’ and ")
  • The values calculated with these formulas do not always match the ones in Blender. (Not sure where the error lies here, could be Blender or the Python script. Metric and BU works fine.)

The two issues may be related. See the attached screenshot for an extreme example: http://www.pasteall.org/pic/41946

Cheers,
Martin

Thank you for pointing it out: I reproduced the problem, and I’ll look at it as soon as possible.

Alessandro

Hi Martin,

I think I’ve fixed the issue (the first version was way more complicated than needed!).

I’ve also fixed a rounding error which could happen (with Metric too) when separate units was on: if a measure was near enough to a unit change (e.g. 99,999999 cm) it would display incorrectly (e.g. 0m 100cm instead of 1m).

Some issue with Imperial still remains. Since meters=feet0,3048 then feet=meters1/0,3048, but 1/0,3048 is an irrational number and thus sometimes the value displayed in the viewport is slightly different from the one displayed in the panels, I suppose because of differences in rounding between Python and the C code in Blender.

Cheers,
Alessandro

Attachments

display_units_r1.zip (855 Bytes)