[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2879] contrib/py/scripts/addons/ object_laplace_lightning.py: moving to contrib/py/scripts/addons/ object_laplace_lightning.py

Brendon Murphy meta.androcto1 at gmail.com
Wed Jan 11 12:48:36 CET 2012


Revision: 2879
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2879
Author:   meta-androcto
Date:     2012-01-11 11:48:33 +0000 (Wed, 11 Jan 2012)
Log Message:
-----------
moving to contrib/py/scripts/addons/object_laplace_lightning.py
small api updates are still needed. 
teldredge already has access to contrib svn

Added Paths:
-----------
    contrib/py/scripts/addons/object_laplace_lightning.py

Added: contrib/py/scripts/addons/object_laplace_lightning.py
===================================================================
--- contrib/py/scripts/addons/object_laplace_lightning.py	                        (rev 0)
+++ contrib/py/scripts/addons/object_laplace_lightning.py	2012-01-11 11:48:33 UTC (rev 2879)
@@ -0,0 +1,1244 @@
+# ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# ***** END GPL LICENCE BLOCK *****
+bl_info = {
+    "name": "Laplacian Lightning",
+    "author": "teldredge",
+    "version": (0, 2, 6),
+    "blender": (2, 6, 1),
+    "api": 43252,
+    "location": "View3D > ToolShelf > Laplacian Lightning",
+    "description": "Lightning mesh generator using laplacian growth algorithm",
+    "warning": "Beta/Buggy.",
+    "wiki_url": "http://www.funkboxing.com/wordpress/?p=301",
+    "tracker_url": "https://projects.blender.org/tracker/index.php?"
+                   "func=detail&aid=27189",
+    "category": "Object"}
+        
+######################################################################
+######################################################################
+##################### BLENDER LAPLACIAN LIGHTNING ####################
+############################ teldredge ###############################
+######################## www.funkboxing.com ##########################
+######################################################################
+######################## using algorithm from ########################
+######################################################################
+############## FAST SIMULATION OF LAPLACIAN GROWTH (FSLG) ############
+#################### http://gamma.cs.unc.edu/FRAC/ ###################
+######################################################################
+###################### and a few ideas ideas from ####################
+######################################################################
+##### FAST ANIMATION OF LIGHTNING USING AN ADAPTIVE MESH (FALUAM) ####
+################ http://gamma.cs.unc.edu/FAST_LIGHTNING/ #############
+######################################################################
+######################################################################
+"""           -----RELEASE LOG/NOTES/PONTIFICATIONS-----
+v0.1.0 - 04.11.11
+    basic generate functions and UI
+    object creation report (Custom Properties: FSLG_REPORT)
+v0.2.0 - 04.15.11
+    started spelling laplacian right.
+    add curve function (not in UI) ...twisting problem
+    classify stroke by MAIN path, h-ORDER paths, TIP paths
+    jitter cells for mesh creation
+    add materials if present
+v0.2.1 - 04.16.11
+    mesh classification speedup
+v0.2.2 - 04.21.11
+    fxns to write/read array to file 
+    restrict growth to insulator cells (object bounding box)
+    origin/ground defineable by object
+    gridunit more like 'resolution'
+v0.2.3 - 04.24.11
+    cloud attractor object (termintates loop if hit)
+    secondary path orders (hOrder) disabled in UI (set to 1)
+v0.2.4 - 04.26.11
+    fixed object selection in UI
+    will not run if required object not selected   
+    moved to view 3d > toolbox
+v0.2.5 - 05.08.11
+    testing for 2.57b
+    single mesh output (for build modifier)
+    speedups (dist fxn)
+v0.2.6 - 06.20.11
+    scale/pos on 'write to cubes' works now
+    if origin obj is mesh, uses all verts as initial charges
+    semi-helpful tooltips
+    speedups, faster dedupe fxn, faster classification
+    use any shape mesh obj as insulator mesh
+        must have rot=0, scale=1, origin set to geometry
+        often fails to block bolt with curved/complex shapes
+    separate single and multi mesh creation
+
+v0.x -
+    -fix vis fxn to only buildCPGraph once for VM or VS
+    -improve list fxns (rid of ((x,y,z),w) and use (x,y,z,w)), use 'sets'
+    -create python cmodule for a few of most costly fxns
+        i have pretty much no idea how to do this yet
+    -cloud and insulator can be groups of MESH objs
+    -?text output, possibly to save on interrupt, allow continue from text
+    -?hook modifiers from tips->sides->main, weight w/ vert groups
+    -user defined 'attractor' path
+    -fix add curve function
+    -animated arcs via. ionization path    
+    -environment map boundary conditions - requires Eqn. 15 from FSLG...
+    -?assign wattage at each segment for HDRI
+    -?default settings for -lightning, -teslacoil, -spark/arc
+    -fix hOrder functionality
+    -multiple 'MAIN' brances for non-lightning discharges
+    -n-symmetry option, create mirror images, snowflakes, etc...
+"""
+
+######################################################################
+######################################################################
+######################################################################
+import bpy
+import time
+import random
+from math import sqrt
+from mathutils import Vector
+import struct
+import bisect
+import os.path
+notZero = 0.0000000001
+scn = bpy.context.scene
+
+######################################################################
+########################### UTILITY FXNS #############################
+######################################################################
+def within(x,y,d):
+###---CHECK IF x-d <= y <= x+d
+    if x-d <= y and x + d >= y:
+        return True
+    else: return False
+
+def dist(ax, ay, az ,bx, by, bz):
+    dv = Vector((ax,ay,az)) - Vector((bx,by,bz))
+    d = dv.length
+    return d
+
+def splitList(aList, idx):
+    ll = []
+    for x in aList:
+        ll.append(x[idx])
+    return ll
+
+def splitListCo(aList):
+    ll = []
+    for p in aList:
+        ll.append((p[0], p[1], p[2]))
+    return ll
+
+def getLowHigh(aList):
+    tLow = aList[0]; tHigh = aList[0]
+    for a in aList:
+        if a < tLow: tLow = a
+        if a > tHigh: tHigh = a
+    return tLow, tHigh
+
+def weightedRandomChoice(aList):
+    tL = []
+    tweight = 0
+    for a in range(len(aList)):
+        idex = a; weight = aList[a]
+        if weight > 0.0:
+            tweight += weight
+            tL.append((tweight, idex))
+    i = bisect.bisect(tL, (random.uniform(0, tweight), None))    
+    r = tL[i][1]
+    return r
+
+def getStencil3D_26(x,y,z):
+    nL = []
+    for xT in range(x-1, x+2):
+        for yT in range(y-1, y+2):
+            for zT in range(z-1, z+2):
+                nL.append((xT, yT, zT))
+    nL.remove((x,y,z))
+    return nL
+
+def jitterCells(aList, jit):
+    j = jit/2
+    bList = []
+    for a in aList:
+        ax = a[0] + random.uniform(-j, j)
+        ay = a[1] + random.uniform(-j, j)
+        az = a[2] + random.uniform(-j, j)
+        bList.append((ax, ay, az))
+    return bList
+
+def deDupe(seq, idfun=None): 
+###---THANKS TO THIS GUY - http://www.peterbe.com/plog/uniqifiers-benchmark
+    if idfun is None:
+        def idfun(x): return x
+    seen = {}
+    result = []
+    for item in seq:
+        marker = idfun(item)
+        if marker in seen: continue
+        seen[marker] = 1
+        result.append(item)
+    return result
+
+######################################################################
+######################## VISUALIZATION FXNS ##########################
+######################################################################
+def writeArrayToVoxel(arr, filename):
+    gridS = 64
+    half = int(gridS/2)
+    bitOn = 255
+    aGrid = [[[0 for z in range(gridS)] for y in range(gridS)] for x in range(gridS)]
+    for a in arr:
+        try:
+            aGrid[a[0]+half][a[1]+half][a[2]+half] = bitOn
+        except:
+            print('Particle beyond voxel domain')
+    file = open(filename, "wb")
+    for z in range(gridS):
+        for y in range(gridS):
+            for x in range(gridS):
+                file.write(struct.pack('B', aGrid[x][y][z]))
+    file.flush()
+    file.close()
+        
+def writeArrayToFile(arr, filename):
+    file = open(filename, "w")
+    for a in arr:
+        tstr = str(a[0]) + ',' + str(a[1]) + ',' + str(a[2]) + '\n'
+        file.write(tstr)
+    file.close
+
+def readArrayFromFile(filename):
+    file = open(filename, "r")
+    arr = []
+    for f in file:
+        pt = f[0:-1].split(',')
+        arr.append((int(pt[0]), int(pt[1]), int(pt[2])))
+    return arr
+
+def makeMeshCube(msize):
+    msize = msize/2
+    mmesh = bpy.data.meshes.new('q')
+    mmesh.vertices.add(8)
+    mmesh.vertices[0].co = [-msize, -msize, -msize]
+    mmesh.vertices[1].co = [-msize,  msize, -msize]
+    mmesh.vertices[2].co = [ msize,  msize, -msize]
+    mmesh.vertices[3].co = [ msize, -msize, -msize]
+    mmesh.vertices[4].co = [-msize, -msize,  msize]
+    mmesh.vertices[5].co = [-msize,  msize,  msize]
+    mmesh.vertices[6].co = [ msize,  msize,  msize]
+    mmesh.vertices[7].co = [ msize, -msize,  msize]
+    mmesh.faces.add(6)
+    mmesh.faces[0].vertices_raw = [0,1,2,3]
+    mmesh.faces[1].vertices_raw = [0,4,5,1]
+    mmesh.faces[2].vertices_raw = [2,1,5,6]
+    mmesh.faces[3].vertices_raw = [3,2,6,7]
+    mmesh.faces[4].vertices_raw = [0,3,7,4]
+    mmesh.faces[5].vertices_raw = [5,4,7,6]
+    mmesh.update(calc_edges=True)
+    return(mmesh)
+
+def writeArrayToCubes(arr, gridBU, orig, cBOOL = False, jBOOL = True):
+    for a in arr:
+        x = a[0]; y = a[1]; z = a[2]
+        me = makeMeshCube(gridBU)
+        ob = bpy.data.objects.new('xCUBE', me)
+        ob.location.x = (x*gridBU) + orig[0]
+        ob.location.y = (y*gridBU) + orig[1]
+        ob.location.z = (z*gridBU) + orig[2]
+        if cBOOL: ###---!!!MOSTLY UNUSED
+            ###   POS+BLUE, NEG-RED, ZERO:BLACK
+            col = (1.0, 1.0, 1.0, 1.0)
+            if a[3] == 0: col = (0.0, 0.0, 0.0, 1.0)
+            if a[3] < 0: col = (-a[3], 0.0, 0.0, 1.0)
+            if a[3] > 0: col = (0.0, 0.0, a[3], 1.0)                
+            ob.color = col

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list