[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2410] branches/geodesic_domes/__init__ .py: added the __init__.py which is a copy of the start1.py , this is the default way for an addon to be seen by blender.

Campbell Barton ideasman42 at gmail.com
Mon Oct 10 01:10:21 CEST 2011


Any reason you're calculating you're own boundbox and not using blenders?

http://www.blender.org/documentation/blender_python_api_2_59_4/bpy.types.Object.html#bpy.types.Object.bound_box

Also, you can replace:

if len(obj.particle_systems) > 0:
....

With:

if obj.particle_systems:
....

Which is faster since it only checks for one or more rather then
counting all members, though in this case its not going to be a
performance problem.

On Mon, Oct 10, 2011 at 8:51 AM, james bond <thekilon at yahoo.co.uk> wrote:
> Revision: 2410
>          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2410
> Author:   kilon
> Date:     2011-10-09 21:51:44 +0000 (Sun, 09 Oct 2011)
> Log Message:
> -----------
> added the __init__.py which is a copy of the start1.py , this is the default way for an addon to be seen by blender. It seems to work with no big issues. From there on we can devide the __init__.py to smaller modules or we can keep everything inside __init__.py
>
> Added Paths:
> -----------
>    branches/geodesic_domes/__init__.py
>
> Added: branches/geodesic_domes/__init__.py
> ===================================================================
> --- branches/geodesic_domes/__init__.py                         (rev 0)
> +++ branches/geodesic_domes/__init__.py 2011-10-09 21:51:44 UTC (rev 2410)
> @@ -0,0 +1,929 @@
> +# ##### BEGIN GPL LICENSE BLOCK #####
> +#
> +#  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.
> +#
> +# ##### END GPL LICENSE BLOCK #####
> +
> +#  first try for an GUI : step1.py will be renamed later
> +bl_info = {
> +    "name": "Geodesic Dome",
> +    "author": "PKHG, Kilon, original for 2.49 from Andy Houston'",
> +    "version": (0,0,1),
> +    "blender": (2, 5, 9),
> +    "api": 39685,
> +    "location": "View3D > Tool Shelf > Geodesic Dome Panel",
> +    "description": "Choice for objects",
> +    "warning": "",
> +    "wiki_url": "",
> +    "tracker_url": "",
> +    "category": "Mesh"}
> +
> +"""
> +Rev 0.1 building menues
> +"""
> +
> +import bpy
> +from math import *
> +from bpy.props import EnumProperty, IntProperty, FloatProperty, StringProperty, BoolProperty
> +import sys
> +
> +typesOfObjects =["Geodesic", "Grid", "Cylinder", "Parabola", "Torus", "Ball", "Your mesh"]
> +
> +
> +sys.path.append("c:\\Users\\Peter\\25blender\\blenderlatest\\2.59\\scripts\\addons\\geodesicDome")
> +#import geodesic259 #AttributeError: 'geodesic' object has no attribute 'vertskeleton'
> +# This routine takes an object and deletes all of the geometry in it
> +# and adds a bounding box to it.
> +# It will add or subtract the bound box size by the variable sizeDifference.
> +
> +
> +
> +def getMeshandPutinEditMode(scene, object):
> +
> +     # Go into Object Mode
> +    bpy.ops.object.mode_set(mode='OBJECT')
> +
> +    # Deselect All
> +    bpy.ops.object.select_all(action='DESELECT')
> +
> +    # Select the object
> +    object.select = True
> +    scene.objects.active = object
> +
> +    # Go into Edit Mode
> +    bpy.ops.object.mode_set(mode='EDIT')
> +
> +    return object.data
> +
> +def maxAndMinVerts(scene, object):
> +
> +    mesh = getMeshandPutinEditMode(scene, object)
> +    verts = mesh.vertices
> +
> +    #Set the max and min verts to the first vertex on the list
> +    maxVert = [verts[0].co[0], verts[0].co[1], verts[0].co[2]]
> +    minVert = [verts[0].co[0], verts[0].co[1], verts[0].co[2]]
> +
> +    #Create Max and Min Vertex array for the outer corners of the box
> +    for vert in verts:
> +        #Max vertex
> +        if vert.co[0] > maxVert[0]:
> +            maxVert[0] = vert.co[0]
> +        if vert.co[1] > maxVert[1]:
> +            maxVert[1] = vert.co[1]
> +        if vert.co[2] > maxVert[2]:
> +            maxVert[2] = vert.co[2]
> +
> +        #Min Vertex
> +        if vert.co[0] < minVert[0]:
> +            minVert[0] = vert.co[0]
> +        if vert.co[1] < minVert[1]:
> +            minVert[1] = vert.co[1]
> +        if vert.co[2] < minVert[2]:
> +            minVert[2] = vert.co[2]
> +
> +    return [maxVert, minVert]
> +
> +def makeObjectIntoBoundBox(scene, object, sizeDifference, takeFromObject):
> +
> +    #Let's find the max and min of the reference object, it can be the same as the destination object
> +    [maxVert, minVert] = maxAndMinVerts(scene, takeFromObject)
> +
> +    #get objects mesh
> +    mesh = getMeshandPutinEditMode(scene, object)
> +
> +    #Add the size difference to the max size of the box
> +    maxVert[0] = maxVert[0] + sizeDifference
> +    maxVert[1] = maxVert[1] + sizeDifference
> +    maxVert[2] = maxVert[2] + sizeDifference
> +
> +    #subtract the size difference to the min size of the box
> +    minVert[0] = minVert[0] - sizeDifference
> +    minVert[1] = minVert[1] - sizeDifference
> +    minVert[2] = minVert[2] - sizeDifference
> +
> +    #Create arrays of verts and faces to be added to the mesh
> +    addVerts = []
> +
> +    #X high loop
> +    addVerts.append([maxVert[0], maxVert[1], maxVert[2]])
> +    addVerts.append([maxVert[0], maxVert[1], minVert[2]])
> +    addVerts.append([maxVert[0], minVert[1], minVert[2]])
> +    addVerts.append([maxVert[0], minVert[1], maxVert[2]])
> +
> +    #x low loop
> +    addVerts.append([minVert[0], maxVert[1], maxVert[2]])
> +    addVerts.append([minVert[0], maxVert[1], minVert[2]])
> +    addVerts.append([minVert[0], minVert[1], minVert[2]])
> +    addVerts.append([minVert[0], minVert[1], maxVert[2]])
> +
> +    # Make the faces of the bounding box.
> +    addFaces = []
> +
> +    # Draw a box on paper and number the vertices.
> +    # Use right hand rule to come up with number orders for faces on
> +    # the box (with normals pointing out).
> +    addFaces.append([0, 3, 2, 1])
> +    addFaces.append([4, 5, 6, 7])
> +    addFaces.append([0, 1, 5, 4])
> +    addFaces.append([1, 2, 6, 5])
> +    addFaces.append([2, 3, 7, 6])
> +    addFaces.append([0, 4, 7, 3])
> +
> +    # Delete all geometry from the object.
> +    bpy.ops.mesh.select_all(action='SELECT')
> +    bpy.ops.mesh.delete(type='ALL')
> +
> +    # Must be in object mode for from_pydata to work
> +    bpy.ops.object.mode_set(mode='OBJECT')
> +
> +    # Add the mesh data.
> +    mesh.from_pydata(addVerts, [], addFaces)
> +
> +    # Update the mesh
> +    mesh.update()
> +
> +def applyScaleRotLoc(scene, obj):
> +    # Deselect All
> +    bpy.ops.object.select_all(action='DESELECT')
> +
> +    # Select the object
> +    obj.select = True
> +    scene.objects.active = obj
> +
> +    bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
> +
> +def totallyDeleteObject(scene, obj):
> +    #remove users?
> +    scene.objects.unlink(obj)
> +    bpy.data.objects.remove(obj)
> +
> +
> +def makeParent(parentobj, childobj, scene):
> +
> +    applyScaleRotLoc(scene, parentobj)
> +    applyScaleRotLoc(scene, childobj)
> +    childobj.parent = parentobj
> +
> +
> +def addNewObject(scene, name, copyobj):
> +
> +    # Create new mesh
> +    mesh = bpy.data.meshes.new(name)
> +
> +    # Create a new object.
> +    ob_new = bpy.data.objects.new(name, mesh)
> +    tempme = copyobj.data
> +    ob_new.data = tempme.copy()
> +    ob_new.scale = copyobj.scale
> +    ob_new.location = copyobj.location
> +
> +    # Link new object to the given scene and select it.
> +    scene.objects.link(ob_new)
> +    ob_new.select = True
> +
> +    return ob_new
> +
> +def getpdensitytexture(object):
> +
> +    for mslot in object.material_slots:
> +        mat = mslot.material
> +        for tslot in mat.texture_slots:
> +            if tslot!= 'NoneType':
> +                tex = tslot.texture
> +                if tex.type == 'POINT_DENSITY':
> +                    if tex.point_density.point_source == 'PARTICLE_SYSTEM':
> +                        return tex
> +
> +def removeParticleSystemFromObj(scene, object):
> +
> +    # Deselect All
> +    bpy.ops.object.select_all(action='DESELECT')
> +
> +    # Select the object.
> +    object.select = True
> +    scene.objects.active = object
> +
> +    bpy.ops.object.particle_system_remove()
> +
> +    # Deselect All
> +    bpy.ops.object.select_all(action='DESELECT')
> +
> +def convertParticlesToMesh(scene, particlesobj, destobj, replacemesh):
> +
> +    # Select the Destination object.
> +    destobj.select = True
> +    scene.objects.active = destobj
> +
> +    #Go to Edit Mode
> +    bpy.ops.object.mode_set(mode='EDIT',toggle=False)
> +
> +    #Delete everything in mesh if replace true
> +    if replacemesh:
> +        bpy.ops.mesh.select_all(action='SELECT')
> +        bpy.ops.mesh.delete(type='ALL')
> +
> +    meshPnts = destobj.data
> +
> +    listCloudParticles = particlesobj.particles
> +
> +    listMeshPnts = []
> +    for pTicle in listCloudParticles:
> +        listMeshPnts.append(pTicle.location)
> +
> +    # Must be in object mode for from_pydata to work.
> +    bpy.ops.object.mode_set(mode='OBJECT')
> +
> +    # Add in the mesh data.
> +    meshPnts.from_pydata(listMeshPnts, [], [])
> +
> +    # Update the mesh.
> +    meshPnts.update()
> +
> +def combineObjects(scene, combined, listobjs):
> +    # scene is the current scene
> +    # combined is the object we want to combine everything into
> +    # listobjs is the list of objects to stick into combined
> +
> +    # Deselect All
> +    bpy.ops.object.select_all(action='DESELECT')
> +
> +    # Select the new object.
> +    combined.select = True
> +    scene.objects.active = combined
> +
> +    # Add data
> +    if (len(listobjs) > 0):
> +            for i in listobjs:
> +                # Add a modifier
> +                bpy.ops.object.modifier_add(type='BOOLEAN')
> +
> +                union = combined.modifiers
> +                union[0].name = "AddEmUp"
> +                union[0].object = i
> +                union[0].operation = 'UNION'
> +
> +                # Apply modifier
> +                bpy.ops.object.modifier_apply(apply_as='DATA', modifier=union[0].name)
> +
> +# Returns the action we want to take
> +def getActionToDo(obj):
> +    return 'GENERATE'
> +    '''
> +    if not obj or obj.type != 'MESH':
> +        return 'NOT_OBJ_DO_NOTHING'
> +    elif obj is None:
> +        return 'NO_SELECTION_DO_NOTHING'
> +    elif "CloudMember" in obj:
> +        if obj["CloudMember"] != None:
> +            if obj["CloudMember"] == "MainObj":
> +                return 'DEGENERATE'
> +            elif obj["CloudMember"] == "CreatedObj" and len(obj.particle_systems) > 0:
> +                return 'CLOUD_CONVERT_TO_MESH'
> +            else:
> +                return 'CLOUD_DO_NOTHING'
> +    elif obj.type == 'MESH':
> +        return 'GENERATE'
> +    else:
> +        return 'DO_NOTHING'
> +    '''
> +
> +class VIEW3D_PT_tools_cloud(bpy.types.Panel):
> +    bl_space_type = 'VIEW_3D'
> +    bl_region_type = 'TOOLS'
> +
> +    bl_label = "Geodesic Dome"
> +    bl_context = "objectmode"
> +
> +
> +    def draw(self, context):
> +        active_obj = context.active_object
> +        layout = self.layout
> +        col = layout.column(align=True)
> +
> +        WhatToDo = getActionToDo(active_obj)
> +
> +        if WhatToDo == 'DEGENERATE':
> +            col.operator("cloud.generate_cloud", text="DeGenerate")
> +
> +        elif WhatToDo == 'CLOUD_CONVERT_TO_MESH':
> +            col.operator("cloud.generate_cloud", text="Convert to Mesh")
> +
> +        elif WhatToDo == 'NO_SELECTION_DO_NOTHING':
> +            col.label(text="Select one or more")
> +            col.label(text="objects to generate")
>
> @@ Diff output truncated at 10240 characters. @@
> _______________________________________________
> Bf-extensions-cvs mailing list
> Bf-extensions-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-extensions-cvs
>



-- 
- Campbell


More information about the Bf-extensions-cvs mailing list