Below is my current code. I get no errors, but when I run the code nothing happens. I'm not even sure everything is right, or when it works will it work how I want. Any feedback or suggestions are helpful. Overall the end result should be a nice looking 3D Mandelbulb with decently high detail, hundreds of thousands of faces are expected if not more.
Code:
import bpy
import numpy as np
import math
def mandelbulb(x, y, z, iterations):
c = x + y*1j + z*1j
z = c
r = 0
for i in range(iterations):
r2 = x*x + y*y + z*z
if r2 > 2:
return i/iterations
theta = math.atan2(math.sqrt(x*x + y*y), z)
phi = math.atan2(y, x)
r = r2**(1/8)
x = r * math.sin(theta/8) * math.cos(phi/8) + c.real
y = r * math.sin(theta/8) * math.sin(phi/8) + c.imag
z = r * math.cos(theta/8)
return 0
def generate_mesh(size, iterations):
vertices = []
faces = []
for x in np.linspace(-2, 2, size):
for y in np.linspace(-2, 2, size):
for z in np.linspace(-2, 2, size):
value = mandelbulb(x, y, z, iterations)
if value > 0:
vertices.append((x, y, z))
return vertices, faces
def create_mesh_object(vertices, faces, name):
mesh = bpy.data.meshes.new(name)
mesh.from_pydata(vertices, [], faces)
mesh.update()
object = bpy.data.objects.new(name, mesh)
bpy.context.collection.objects.link(object)
def execute(size, iterations):
vertices, faces = generate_mesh(size, iterations)
create_mesh_object(vertices, faces, "Mandelbulb")
class MandelbulbOperator(bpy.types.Operator):
bl_idname = "object.mandelbulb_operator"
bl_label = "Mandelbulb Operator"
bl_options = {'REGISTER', 'UNDO'}
size = bpy.props.IntProperty(
name="Size",
default=32,
min=1,
max=256,
step=1,
precision=0
)
iterations = bpy.props.IntProperty(
name="Iterations",
default=64,
min=1,
max=512,
step=1,
precision=0
)
def execute(self, context):
execute(self.size, self.iterations)
return {'FINISHED'}
def draw(self, context):
layout = self.layout
layout.label(text="Create a 3D Mandelbulb")
layout.prop(self, "size")
layout.prop(self, "iterations")
def register():
bpy.utils.register_class(MandelbulbOperator)
def unregister():
bpy.utils.unregister_class(MandelbulbOperator)
if __name__ == "__main__":
register()
```




=with:in the operator properties definition (not those beiginng withbl_+precisionis an invalid argument for IntProperty, remove it in bothsizeanditerations$\endgroup$