Wednesday June 25, 2025
Home
|
Contact
|
Support
|
Blender (.py) Scripts... Automating Blender ..
<<
Random Page
Programming
C/C++
C# (with .net)
Win32/Win64
RegEx
Markdown (.md)
Python (.py)
Batch (.bat)
Blender Scripting
Programming XBOX & 360
XDK Tuts
NonXDK Tuts
OpenXDK Tuts
XNA with C#
Tutorials
Win32/Win64
DirectX3D (DirectX)
Maths of 3D
ASM..10101
Java
Physics
Visual Studio
Vulkan
Graphics
LaTeX
Data Mining & Machine Learning
AI
Fractals
Dual-Quaternions
Shaders
Vertex & Pixel Asm
Cg
Effect Files (.fx)
GLSL (.glsl)
WGSL (.wgsl)
Executable File Formats
PE (.exe) Inside Out
XBOX (.xbe) Format
Android (.apk)
3D File Formats
Quake2 (.md2) Format
Quake3 (.md3) Format
Quake3 BSP (.bsp)
3DS Format (.3ds)
X DirectX (.x)
GLTF (.glTF/.glb)
...
Image Formats
Bitmap (.bmp)
JPEG (.jpg)
DirectX DDS
Flash SWF
PNG (.png)
GIF (.gif)
WebP (.webp)
...
Internet Programming
WinSock
PHP
JavaScript
WebGL
WebXR
Retro Games
WebGPU
WebNN
Projects
Misc Demos
Notebook
Pixels
TexLive (LaTeX)
Crosswords
eNotes
Media
Quotes
Evolve
HSK
Slides
Trending
WordSearch
Links
Recommended Books
Donations (PayPal)
Contact
Books
Amazon
Blender (.py) Scripts...
Automating Blender ..
Particles
Decompose the mesh into particle points (either random size and location or fixed grid like configuration).
Take a mesh and cover it in particles (mesh made of particle spheres).
import bpy
from mathutils import Vector
# Clear existing objects
bpy
.
ops
.
object
.
select_all
(
action
=
'SELECT'
)
bpy
.
ops
.
object
.
delete
()
# Create text object
bpy
.
ops
.
object
.
text_add
(
align
=
'WORLD'
,
location
=(
0
, -
0.2
,
0
))
text_obj
=
bpy
.
context
.
object
text_obj
.
name
=
"BALLS_Emitter"
text_obj
.
data
.
body
=
"BALLS"
text_obj
.
data
.
align_x
=
'CENTER'
text_obj
.
data
.
extrude
=
0.1
text_obj
.
data
.
bevel_depth
=
0.01
#text_obj.data.bevel_resolution = 2
# Convert text to mesh
bpy
.
ops
.
object
.
convert
(
target
=
'MESH'
)
# Create instance object (sphere)
bpy
.
ops
.
mesh
.
primitive_uv_sphere_add
(
radius
=
0.1
,
location
=(
10
,
0
,
0
))
sphere
=
bpy
.
context
.
object
sphere
.
name
=
"BALL_Instance"
sphere
.
hide_render
=
True
# Hide in renders (only particles will show)
# Hide the emitter text
#text_obj.hide_set(True)
#text_obj.hide_render = True
# Add particle system
particle_system
=
text_obj
.
modifiers
.new(
name
=
"ParticleSystem"
,
type
=
'PARTICLE_SYSTEM'
)
particles
=
particle_system
.
particle_system
.
settings
# Configure particle settings
particles
.
count
=
2500
particles
.
frame_start
=
1
particles
.
frame_end
=
1
particles
.
lifetime
=
10
particles
.
emit_from
=
'FACE'
particles
.
physics_type
=
'NO'
particles
.
normal_factor
=
0
particles
.
factor_random
=
3
particles
.
particle_size
=
0.45
particles
.
size_random
=
0.3
particles
.
distribution
=
'RAND'
# THIS SETS RANDOM DISTRIBUTION
# Set particles to use sphere instance
particles
.
render_type
=
'OBJECT'
particles
.
instance_object
=
sphere
particles
.
use_rotation_instance
=
True
particles
.
use_scale_instance
=
True
# Create material for spheres
mat
=
bpy
.
data
.
materials
.new(
name
=
"BallMaterial"
)
mat
.
use_nodes
=
True
nodes
=
mat
.
node_tree
.
nodes
links
=
mat
.
node_tree
.
links
nodes
.
clear
()
# Create glossy shader with random color per particle
bsdf
=
nodes
.new(
'ShaderNodeBsdfPrincipled'
)
bsdf
.
inputs
[
'Base Color'
].
default_value
= (
0.8
,
0.2
,
0.1
,
1
)
bsdf
.
inputs
[
'Metallic'
].
default_value
=
0.5
bsdf
.
inputs
[
'Roughness'
].
default_value
=
0.3
# Add attribute node for random color
attribute
=
nodes
.new(
'ShaderNodeAttribute'
)
attribute
.
attribute_name
=
'random'
# Add hue/saturation node
hue_sat
=
nodes
.new(
'ShaderNodeHueSaturation'
)
hue_sat
.
inputs
[
'Hue'
].
default_value
=
0.5
hue_sat
.
inputs
[
'Saturation'
].
default_value
=
1.0
hue_sat
.
inputs
[
'Value'
].
default_value
=
1.0
# Connect nodes
links
.new(
attribute
.
outputs
[
'Color'
],
hue_sat
.
inputs
[
'Color'
])
links
.new(
hue_sat
.
outputs
[
'Color'
],
bsdf
.
inputs
[
'Base Color'
])
output
=
nodes
.new(
'ShaderNodeOutputMaterial'
)
links
.new(
bsdf
.
outputs
[
'BSDF'
],
output
.
inputs
[
'Surface'
])
# Assign material to sphere
if
sphere
.
data
.
materials
:
sphere
.
data
.
materials
[
0
] =
mat
else:
sphere
.
data
.
materials
.
append
(
mat
)
# Set up lighting
bpy
.
ops
.
object
.
light_add
(
type
=
'SUN'
,
location
=(
5
,
5
,
10
))
sun
=
bpy
.
context
.
object
sun
.
data
.
energy
=
3.0
bpy
.
ops
.
object
.
light_add
(
type
=
'AREA'
,
location
=(
0
, -
5
,
5
))
area
=
bpy
.
context
.
object
area
.
data
.
energy
=
500
area
.
data
.
size
=
2.0
# Set up camera
bpy
.
ops
.
object
.
camera_add
(
location
=(
0
,
0
,
4
))
camera
=
bpy
.
context
.
object
camera
.
rotation_euler
= (
0
,
0
,
0
)
bpy
.
context
.
scene
.
camera
=
camera
bpy
.
context
.
scene
.
frame_set
(
1
)
Advert (Support Website)
Visitor:
Copyright (c) 2002-2025 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.