Special welcome gift. Get 30% off your first purchase with code “REALCG”. Find out more!

Blender 2D Image to 3D Model using ChatGPT – Blender Tutorial

In this tutorial, I’ll show you how to turn a 2D image into a 3D model in Blender using AI. We’ll use a Python script generated by ChatGPT to create a wine glass model from a 2D reference image.

1. Know the Approach

The traditional way of modeling a wine glass would be tricky for AI, but using a Python script, we can generate the model easily. We’ll use the Screw Modifier in Blender to revolve vertices around the Z-axis based on the shape of the glass.

2. Write the Prompt for ChatGPT

Upload your reference image and prompt ChatGPT with the following:

Prompt Example:

“Write a Python script for Blender to create a 3D model of a wine glass.
Generate vertices that follow the green line highlighted in the reference image.
Use the red dot as the center point.
Use the Screw Modifier to revolve the vertices around the Z-axis with a 360-degree angle to form the wine glass.”

3. Execute the Python Script

After getting the script from ChatGPT, copy and paste it into Blender’s text editor and run it. Your 3D wine glass will be created instantly!

Python Script:

python
import bpy
 import bmesh
# Create a new mesh and object
mesh = bpy.data.meshes.new(“WineGlass”)
obj = bpy.data.objects.new(“WineGlass”, mesh)# Link the object to the current scene
bpy.context.collection.objects.link(obj)
bpy.context.view_layer.objects.active = obj
obj.select_set(True)# Use BMesh to create vertices along the wine glass profile
bm = bmesh.new()

# Coordinates for vertices along the profile (approximation)
vertices = [
(0.35, 0.0, –0.02),
(0.35, 0.0, 0.0),
(0.24, 0.0, 0.025),
(0.07, 0.0, 0.05),
(0.03, 0.0, 0.09), # Base center point (Red dot)
(0.03, 0.0, 0.8), # Slightly to the right of the base center
(0.2, 0.0, 0.85), # Start of the stem
(0.4, 0.0, 1.15), # End of the stem
(0.5, 0.0, 1.45), # Bottom of the bowl
(0.35, 0.0, 2.1), # Mid-bowl
(0.35, 0.0, 2.15), # Top of the bowl
]

# Add vertices to the BMesh
for v_co in vertices:
bm.verts.new(v_co)

# Ensure vertices are updated
bm.verts.ensure_lookup_table()

# Create edges between consecutive vertices
for i in range(len(vertices) – 1):
bm.edges.new((bm.verts[i], bm.verts[i + 1]))

# Update the mesh with the BMesh data
bm.to_mesh(mesh)
bm.free()

# Set the origin of the object to the base (for symmetry)
bpy.ops.object.origin_set(type=‘ORIGIN_CURSOR’, center=‘BOUNDS’)

# Apply the Screw Modifier to create the 3D shape
screw_mod = obj.modifiers.new(“Screw”, type=‘SCREW’)
screw_mod.axis = ‘Z’ # Rotate around Z-axis
screw_mod.steps = 32 # Adjust steps for smoothness
screw_mod.render_steps = 32
screw_mod.use_merge_vertices = True

# Apply a Subdivision Surface Modifier for extra smoothness
subdiv_mod = obj.modifiers.new(“Subdivision”, type=‘SUBSURF’)
subdiv_mod.levels = 2 # Viewport subdivision level
subdiv_mod.render_levels = 2 # Render subdivision level

# Switch to object mode and view the final result
bpy.ops.object.mode_set(mode=‘OBJECT’)

# Optional: Apply Shade Smooth for a smoother look
bpy.ops.object.shade_smooth()

 

Conclusion

After getting the script from ChatGPT, copy and paste it into Blender’s text editor and run it. Your 3D wine glass will be created instantly!

By following these simple steps, you’ll be able to create detailed 3D models quickly with the help of AI!

Abdelilah Hamdani is a 3D Designer and a Developer. I firmly believe that Photorealism is gonna be one of the most valuable skills in the near future. There is alot of opportunities for CGI artists: VFX, Gaming, Movies & Series. More than 6 years in the 3D Industry and i humbly admit i've got alot more to learn.

Leave A Reply

Your email address will not be published. Required fields are marked *