Add mesh style lamp.
This commit is contained in:
parent
11d306f362
commit
29f788385d
7 changed files with 70 additions and 27 deletions
Binary file not shown.
|
@ -1,5 +1,5 @@
|
|||
import bpy
|
||||
from mathutils import Vector
|
||||
from mathutils import Vector, Euler
|
||||
import bmesh
|
||||
import math
|
||||
|
||||
|
@ -85,31 +85,74 @@ def generate_cone_shade(radius1, radius2, depth):
|
|||
|
||||
def generate_mesh_shade(radius1, radius2, depth):
|
||||
|
||||
bpy.ops.mesh.primitive_cone_add(radius1=radius1,
|
||||
radius2=radius2,
|
||||
depth=depth)
|
||||
cone = bpy.data.objects["Cone"]
|
||||
cone.name = "shade"
|
||||
bpy.ops.mesh.primitive_cube_add(radius=radius1)
|
||||
cube = bpy.data.objects["Cube"]
|
||||
cube.name = "shade"
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
bm = bmesh.from_edit_mesh(cone.data)
|
||||
for face in bm.faces:
|
||||
if UpOrDown(face.normal):
|
||||
face.select = True
|
||||
else:
|
||||
face.select = False
|
||||
faces_select = [f for f in bm.faces if f.select]
|
||||
bmesh.ops.delete(bm, geom=faces_select, context=3)
|
||||
bmesh.update_edit_mesh(cone.data, True)
|
||||
|
||||
# Extrude faces
|
||||
bpy.ops.mesh.select_mode( type = 'FACE' )
|
||||
bpy.ops.mesh.select_all( action = 'SELECT' )
|
||||
bpy.ops.mesh.extrude_region_move(
|
||||
TRANSFORM_OT_translate={"value":(0, 0, 0.01)} )
|
||||
bpy.ops.mesh.extrude_region_shrink_fatten(
|
||||
TRANSFORM_OT_shrink_fatten={"value":-0.05})
|
||||
for idx in range(3):
|
||||
bpy.ops.mesh.subdivide()
|
||||
|
||||
bm = bmesh.from_edit_mesh(cube.data)
|
||||
for i in range( len( bm.verts ) ):
|
||||
bm.verts.ensure_lookup_table()
|
||||
vert = bm.verts[i]
|
||||
#theta = math.atan2(vert.co.x, vert.co.y)
|
||||
vert.co.z = vert.co.z - radius1
|
||||
vert.co.z = vert.co.z*2.0
|
||||
height = radius1*2.0
|
||||
vert.co.y = vert.co.y*0.03
|
||||
vert.co.x = vert.co.x*0.1 + radius1/2.0
|
||||
theta = abs(vert.co.z/height)
|
||||
vert.co.x = vert.co.x + 2.0*radius1*math.sin(theta)
|
||||
vert.co.z = vert.co.z + 1.0*radius1
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
return cone
|
||||
|
||||
num_slats = 36
|
||||
cube_copy = cube.data.copy()
|
||||
for idx in range(num_slats-1):
|
||||
ob = bpy.data.objects.new("Cube Copy"+str(idx), cube_copy)
|
||||
angle = 2.0*(math.pi/float(num_slats))*float(idx+1)
|
||||
ob.rotation_euler = Euler((0.0, 0.0, angle), 'XYZ')
|
||||
scene = bpy.context.scene
|
||||
scene.objects.link(ob)
|
||||
scene.update()
|
||||
|
||||
# Add torus
|
||||
bpy.ops.mesh.primitive_torus_add(location=(0.0, 0.0, -2.6*radius1),
|
||||
major_radius=2.4*radius1,
|
||||
minor_radius=0.02)
|
||||
|
||||
for ob in bpy.context.scene.objects:
|
||||
if ob.type == 'MESH':
|
||||
ob.select = True
|
||||
bpy.context.scene.objects.active = ob
|
||||
else:
|
||||
ob.select = False
|
||||
bpy.ops.object.join()
|
||||
|
||||
# mapped_rad = radius2 + delta**2
|
||||
# vert.co.x = mapped_rad*math.sin(theta)
|
||||
# vert.co.y = mapped_rad*math.cos(theta)
|
||||
#
|
||||
# for face in bm.faces:
|
||||
# if UpOrDown(face.normal):
|
||||
# face.select = True
|
||||
# else:
|
||||
# face.select = False
|
||||
# faces_select = [f for f in bm.faces if f.select]
|
||||
# bmesh.ops.delete(bm, geom=faces_select, context=3)
|
||||
# bmesh.update_edit_mesh(cone.data, True)
|
||||
#
|
||||
# # Extrude faces
|
||||
# bpy.ops.mesh.select_mode( type = 'FACE' )
|
||||
# bpy.ops.mesh.select_all( action = 'SELECT' )
|
||||
# bpy.ops.mesh.extrude_region_move(
|
||||
# TRANSFORM_OT_translate={"value":(0, 0, 0.01)} )
|
||||
# bpy.ops.mesh.extrude_region_shrink_fatten(
|
||||
# TRANSFORM_OT_shrink_fatten={"value":-0.05})
|
||||
|
||||
return cube
|
||||
|
||||
def generate_bio_shade(radius1, radius2, depth):
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1 +1 @@
|
|||
{"color": [0.1, 0.1, 0.1], "height": 1.5, "radius": 0.5, "shape": "pendant"}
|
||||
{"color": [0.1, 0.1, 0.1], "shape": "mesh", "radius": 0.8, "height": 1.5}
|
Binary file not shown.
Before Width: | Height: | Size: 295 KiB After Width: | Height: | Size: 312 KiB |
|
@ -7,14 +7,14 @@ from argparse import ArgumentParser
|
|||
|
||||
if __name__ == "__main__":
|
||||
|
||||
shape = "pendant"
|
||||
shape = "mesh"
|
||||
output = "test"
|
||||
|
||||
if not os.path.exists(os.getcwd() + "/" + output):
|
||||
os.makedirs(os.getcwd() + "/" + output)
|
||||
|
||||
height = 1.5
|
||||
radius = 0.5
|
||||
radius = 0.8
|
||||
color = [0.1, 0.1, 0.1]
|
||||
|
||||
product_gen.generate_product.generate(shape, height, radius, color, output)
|
||||
|
|
Loading…
Reference in a new issue