[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3783] branches/protopipe: Physical parts
Aurel W
aurel.w at gmail.com
Thu Sep 20 23:32:13 CEST 2012
Revision: 3783
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3783
Author: aurel
Date: 2012-09-20 21:32:12 +0000 (Thu, 20 Sep 2012)
Log Message:
-----------
Physical parts
Modified Paths:
--------------
branches/protopipe/TODO
branches/protopipe/jointproto.py
branches/protopipe/modelbuilder.py
branches/protopipe/pipeproto.py
Added Paths:
-----------
branches/protopipe/parts.py
Modified: branches/protopipe/TODO
===================================================================
--- branches/protopipe/TODO 2012-09-20 15:34:02 UTC (rev 3782)
+++ branches/protopipe/TODO 2012-09-20 21:32:12 UTC (rev 3783)
@@ -1,9 +1,10 @@
* Make numpy optional
-+ (DONE) Mapping
++(DONE) Mapping
* length check
* Apply model transformations
* Make deviation tollerance controlable
* Apply mesh modifiers
+* GUI tools to set part properties in a lbibrary (cost, mass,...)
=== LongTerm ===
Modified: branches/protopipe/jointproto.py
===================================================================
--- branches/protopipe/jointproto.py 2012-09-20 15:34:02 UTC (rev 3782)
+++ branches/protopipe/jointproto.py 2012-09-20 21:32:12 UTC (rev 3783)
@@ -27,6 +27,7 @@
import itertools
from protopipe.utils import *
+from protopipe.parts import Part, PartType
class JointProto:
@@ -138,7 +139,7 @@
right transformation.
"""
if not self.quickDescriptorCheck(descriptor):
- print ("quick descritpr check failed")
+ #print ("quick descritpr check failed")
return (False, None)
# the prototype matrix
@@ -148,7 +149,7 @@
# try all possible pairings until a fit is found
for md in itertools.permutations(descriptor_mat):
- print("permutation...")
+ #print("permutation...")
### calculate the optimal superposition for the pairing ###
correlation_mat = numpy.dot ( numpy.transpose(mp), md)
v, s, w_tr = numpy.linalg.svd(correlation_mat)
@@ -168,7 +169,7 @@
angle = math.acos(clamp11(dot))
if angle > 0.01:
- print("deviation angle too high")
+ #print("deviation angle too high")
deviation_error = True
break
@@ -212,12 +213,13 @@
modelInstance - A mesh object for the joint.
"""
- def __init__(self, jproto, descriptor, rot_mat, mapping, modelInstance=None):
+ def __init__(self, jproto, descriptor, rot_mat, mapping, modelInstance=None, part=Part()):
self.rot_mat = rot_mat
self.mapping = mapping
self.jproto = jproto
self.descriptor = descriptor
self.modelInstance = modelInstance
+ self.part = part
@@ -306,16 +308,12 @@
# find a model and assign it
modelName = tname[:-5] + "model"
if modelName in objects:
- print("insert a model: ", modelName, objects[modelName])
+ #print("insert a model: ", modelName, objects[modelName])
jproto.setModel(objects[modelName])
- else:
- print("no model found")
# append to lib
self.protos.append(jproto)
bpy.data.scenes[self.name].update()
- for obj in bpy.data.objects:
- print("objname: ", obj.name)
def search(self, descriptor):
@@ -328,16 +326,30 @@
### instanciate the model object here ###
model = jr.jproto.model
nobj = bpy.data.objects[model.name].copy()
+
+ ### further process the registration specialezed
+ # for the library and ProtoJoint. ###
jr.modelInstance = nobj
bpy.context.scene.objects.link(nobj)
+ # load physical part description into the JointRegistration
+ self.loadPart(jr)
return (True, jr)
return (False, None)
+ def loadPart(self, jr):
+ jr.part.partType = PartType.JOINT
+ if 'pp_mass' in jr.jproto.model.id_data:
+ jr.part.mass = jr.jproto.model["pp_mass"]
+ if 'pp_cost' in jr.jproto.model.id_data:
+ jr.part.cost = jr.jproto.model["pp_cost"]
+ jr.part.protoName = jr.jproto.name
+
+
class JointFactory:
def __init__(self):
Modified: branches/protopipe/modelbuilder.py
===================================================================
--- branches/protopipe/modelbuilder.py 2012-09-20 15:34:02 UTC (rev 3782)
+++ branches/protopipe/modelbuilder.py 2012-09-20 21:32:12 UTC (rev 3783)
@@ -22,6 +22,9 @@
import math
+from protopipe import ppapp
+from protopipe.utils import *
+
from protopipe.jointproto import JointProto
from protopipe.jointproto import JointDescriptor
from protopipe.jointproto import ProtoLibrary
@@ -30,12 +33,11 @@
from protopipe.pipeproto import PipeProto
from protopipe.pipeproto import PipeFactory
from protopipe.pipeproto import PipeDescriptor
+from protopipe.pipeproto import PipeRegistration
-from protopipe import ppapp
-from protopipe.utils import *
+from protopipe.parts import PartList, Part
-
class ModelBuilder:
def __init__(self, obj):
@@ -45,6 +47,9 @@
self.buildLayer = 1
self.defaultDiameter = 0.2
+ self.modelObjects = []
+ self.partList = PartList()
+
# generating the name for new objects
self.nextJointName = self.nextJointNameGen().__next__
self.nextPipeName = self.nextPipeNameGen().__next__
@@ -103,6 +108,11 @@
# get a new pipe
(isreg, pipeReg) = ppapp.pipeFactory.getProto(desc)
self.insertPipe(vert.co, vec, pipeReg)
+
+ ### process the partlist ###
+ self.partList.computeStats()
+ print("Build Mass: ", self.partList.mass, "g")
+ print("Build Cost: ", self.partList.cost, "€")
@@ -119,13 +129,14 @@
model.rotation_euler = bmat.to_euler()
# set the name
model.name = self.nextJointName()
+ self.modelObjects.append(model)
+ self.partList.addPart(jr.part)
def insertPipe(self, co, vec, pipeReg):
# - Translate by the in-length or have the model created accordingly
model = pipeReg.modelInstance
model.location = co + vec
- # - Get the edge vector
# - Specify a axis where the pipe is oriented as a Vector
zaxis = mathutils.Vector((0,0,1))
# - Compute the cross product between those two vectors
@@ -134,15 +145,15 @@
# - Compute the angle between both vectors
# ... and invert transformation
aangle = math.acos( clamp11(zaxis.dot(vec.normalized())) ) * -1.0
- print("aangle: ", aangle)
- # - Rotate by the quaternion
+ # - Rotate by the axis angle
model.rotation_mode = 'AXIS_ANGLE'
model.rotation_axis_angle = [aangle, aavec[0], aavec[1], aavec[2]]
# - Bake that Cake!
model.name = self.nextPipeName()
+ self.modelObjects.append(model)
+ self.partList.addPart(pipeReg.part)
-
def nextJointNameGen(self):
i = 0
while True:
Added: branches/protopipe/parts.py
===================================================================
--- branches/protopipe/parts.py (rev 0)
+++ branches/protopipe/parts.py 2012-09-20 21:32:12 UTC (rev 3783)
@@ -0,0 +1,71 @@
+#
+# Copyright 2012, Aurel Wildfellner.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+class PartType:
+ NONE = 0
+ JOINT = 1
+ PIPE = 2
+
+
+class Part:
+
+ def __init__(self):
+ self.partType = PartType.NONE
+ self.mass = 0.0
+ self.cost = 0.0
+ self.length = 0.0
+ self.protoName = ""
+ self.partName = ""
+
+
+ def __eq__(self, op):
+ if op.partType != self.partType:
+ return False
+ if op.length != self.length:
+ return False
+ if op.partName != self.partName:
+ return False
+ return True
+
+
+
+
+class PartList:
+
+ def __init__(self):
+ self.parts = []
+
+
+ def addPart(self, part):
+ self.parts.append(part)
+
+
+ def computeStats(self):
+ self.mass = sum( (part.mass for part in self.parts) )
+ self.cost = sum( (part.cost for part in self.parts) )
+
+
+ def compactList(self):
+ compactList = []
+ for part in set(self.parts):
+ compactList.append( (self.parts.count(part), part) )
+ compactList.sort()
+ return compactList
+
+
+
Modified: branches/protopipe/pipeproto.py
===================================================================
--- branches/protopipe/pipeproto.py 2012-09-20 15:34:02 UTC (rev 3782)
+++ branches/protopipe/pipeproto.py 2012-09-20 21:32:12 UTC (rev 3783)
@@ -23,7 +23,9 @@
from protopipe.utils import *
+from protopipe.parts import Part, PartType
+
class PipeProto:
def __init__(self, length=0.0, diameter=0.0, insideDiameter=0.0, model=None, name=""):
@@ -32,6 +34,7 @@
self.insideDiameter = insideDiameter
self.model = model
self.name = name
+ self.numVerts = 128
def registerDescriptor(self, descriptor):
@@ -39,7 +42,7 @@
self.diameter = descriptor.diameter
# generate the acording mesh object
- bpy.ops.mesh.primitive_cylinder_add(radius=self.diameter)
+ bpy.ops.mesh.primitive_cylinder_add(radius=self.diameter, vertices=self.numVerts)
model = bpy.context.active_object
model.scale[2] = (self.length/2.0)
self.model = model
@@ -68,10 +71,11 @@
No transformation to a mesh-edge is specified.
"""
- def __init__(self, pipeProto, descriptor, modelInstance=None):
+ def __init__(self, pipeProto, descriptor, modelInstance=None, part=Part()):
self.descriptor = descriptor
self.pipeProto = pipeProto
self.modeInstance = modelInstance
+ self.part = part
@@ -98,10 +102,21 @@
# the prototype is single, so use model as instance
pReg.modelInstance = pReg.pipeProto.model
if isreg:
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list