I got a friend who was adamant for a while that python was the best non-C++ language to work out what to do. I ended up with this:
I now just have the issues that Blender freezes after a script runs for more than a few seconds, and that, although the api says I'm doing it right, mat.type = 'VOLUME' crashes the script. Given how long it took to find that bit of the API, I'm not sure anyone actually knows what I'm supposed to do.
Code:
import bpy
import mathutils
import math
class MakeOneSOrbital(bpy.types.Operator):
bl_idname = "mesh.make_one_s_orbital"
bl_label = "Add 1s Orbital"
def invoke(self, context, event):
e = 2.71828182845904523536028747135266249775724709369995
psimax=0
psimin=2**31
res = 50
multi = 2*res
cubedim = 2.5/res
stretch = 5/res
psilist = [[[0 for k in range(res*2+1)] for j in range(res*2+1)] for i in range(res*2+1)]
for x in range(-res,res+1):
for y in range(-res,res+1):
for z in range(-res,res+1):
xco = x/multi
yco = y/multi
zco = z/multi
r = xco**2 + yco**2 + zco**2
r = r**0.5
psi=e**-r
if psi > psimax:
psimax = psi
if psi < psimin:
psimin = psi
psilist[x+res][y+res][z+res] = psi
print(psimax,psimin)
for x in range(-res,res+1):
for y in range(-res,res+1):
for z in range(-res,res+1):
xco = x/stretch
yco = y/stretch
zco = z/stretch
bpy.ops.mesh.primitive_cube_add(location=(xco,yco,zco))
bpy.ops.transform.resize(value=(cubedim,cubedim,cubedim))
mat = bpy.ops.material.new()
mat.type = 'VOLUME'
mat.volume.density = psimax/psilist[x+res][y+res][z+res]
return {"FINISHED"}
bpy.utils.register_class(MakeOneSOrbital)I now just have the issues that Blender freezes after a script runs for more than a few seconds, and that, although the api says I'm doing it right, mat.type = 'VOLUME' crashes the script. Given how long it took to find that bit of the API, I'm not sure anyone actually knows what I'm supposed to do.
OS: Windows 10 64 bit Professional
CPU: AMD Ryzen 5900X
RAM: 16GB
GPU: Radeon Vega 56
CPU: AMD Ryzen 5900X
RAM: 16GB
GPU: Radeon Vega 56
