2 # very simple 'pixelization' or 'voxelization' engine #
9 "location": "View3D > Tool Shelf",
10 "description": "Creates a 3d pixelated version of the object",
13 # Note: winmgr properties are moved to the operator
17 from bpy
.types
import Operator
18 from bpy
.props
import (
25 sce
= bpy
.context
.scene
26 obj
.hide
= obj
.hide_render
= True
27 mes
= obj
.to_mesh(sce
, True, 'RENDER')
28 mes
.transform(obj
.matrix_world
)
29 dup
= bpy
.data
.objects
.new('dup', mes
)
31 dup
.dupli_type
= 'VERTS'
32 sce
.objects
.active
= dup
33 bpy
.ops
.object.mode_set()
38 for i
in dup
.data
.edges
:
39 d
= ver
[i
.vertices
[0]].co
- ver
[i
.vertices
[1]].co
40 if d
.length
> self
.size
:
41 ver
[i
.vertices
[0]].select
= True
42 ver
[i
.vertices
[1]].select
= True
44 bpy
.ops
.object.editmode_toggle()
45 bpy
.ops
.mesh
.subdivide(number_cuts
=1, smoothness
=self
.smooth
)
46 bpy
.ops
.mesh
.select_all(action
='DESELECT')
47 bpy
.ops
.object.editmode_toggle()
53 i
.co
[n
] -= (.001 + i
.co
[n
]) % self
.size
55 bpy
.ops
.object.mode_set(mode
='EDIT', toggle
=False)
56 bpy
.ops
.mesh
.select_all(action
='SELECT')
57 bpy
.ops
.mesh
.remove_doubles(threshold
=0.0001)
58 bpy
.ops
.mesh
.delete(type='EDGE_FACE')
59 bpy
.ops
.object.mode_set()
60 sca
= self
.size
* (100 - self
.gap
) * .005
61 bpy
.ops
.mesh
.primitive_cube_add(layers
=[True] + [False] * 19)
62 bpy
.ops
.transform
.resize(value
=[sca
] * 3)
63 bpy
.context
.scene
.objects
.active
= dup
64 bpy
.ops
.object.parent_set(type='OBJECT')
67 class Pixelate(Operator
):
68 bl_idname
= "object.pixelate"
69 bl_label
= "Pixelate Object"
70 bl_description
= ("Create a 3d pixelated version of the object\n"
71 "using a Duplivert Box around each copied vertex\n"
72 "With high poly objects, it can take some time\n"
73 "Needs an existing Active Mesh Object")
74 bl_options
= {'REGISTER', 'UNDO'}
80 description
="Size of the cube / grid \n"
81 "Small values (below 0.1) can create a high polygon count"
88 description
="Separation - percent of size"
90 smooth
= FloatProperty(
94 description
="Smooth factor when subdividing mesh"
98 def poll(cls
, context
):
99 return (context
.active_object
and
100 context
.active_object
.type == 'MESH' and
101 context
.mode
== 'OBJECT')
103 def draw(self
, context
):
106 col
= layout
.column(align
=True)
107 col
.prop(self
, "size")
108 col
.prop(self
, "gap")
109 layout
.prop(self
, "smooth")
111 def execute(self
, context
):
112 objeto
= bpy
.context
.object
116 except Exception as e
:
117 self
.report({'WARNING'},
118 "Some operations could not be performed (See Console for more info)")
120 print("\n[Add Advanced Objects]\nOperator: "
121 "object.pixelate\nError: {}".format(e
))
129 bpy
.utils
.register_class(Pixelate
)
133 bpy
.utils
.unregister_class(Pixelate
)
136 if __name__
== '__main__':