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
|
import bpy
|
||||||
from mathutils import Vector
|
from mathutils import Vector, Euler
|
||||||
import bmesh
|
import bmesh
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
@ -85,31 +85,74 @@ def generate_cone_shade(radius1, radius2, depth):
|
||||||
|
|
||||||
def generate_mesh_shade(radius1, radius2, depth):
|
def generate_mesh_shade(radius1, radius2, depth):
|
||||||
|
|
||||||
bpy.ops.mesh.primitive_cone_add(radius1=radius1,
|
bpy.ops.mesh.primitive_cube_add(radius=radius1)
|
||||||
radius2=radius2,
|
cube = bpy.data.objects["Cube"]
|
||||||
depth=depth)
|
cube.name = "shade"
|
||||||
cone = bpy.data.objects["Cone"]
|
|
||||||
cone.name = "shade"
|
|
||||||
bpy.ops.object.mode_set(mode='EDIT')
|
bpy.ops.object.mode_set(mode='EDIT')
|
||||||
bm = bmesh.from_edit_mesh(cone.data)
|
|
||||||
for face in bm.faces:
|
for idx in range(3):
|
||||||
if UpOrDown(face.normal):
|
bpy.ops.mesh.subdivide()
|
||||||
face.select = True
|
|
||||||
else:
|
bm = bmesh.from_edit_mesh(cube.data)
|
||||||
face.select = False
|
for i in range( len( bm.verts ) ):
|
||||||
faces_select = [f for f in bm.faces if f.select]
|
bm.verts.ensure_lookup_table()
|
||||||
bmesh.ops.delete(bm, geom=faces_select, context=3)
|
vert = bm.verts[i]
|
||||||
bmesh.update_edit_mesh(cone.data, True)
|
#theta = math.atan2(vert.co.x, vert.co.y)
|
||||||
|
vert.co.z = vert.co.z - radius1
|
||||||
# Extrude faces
|
vert.co.z = vert.co.z*2.0
|
||||||
bpy.ops.mesh.select_mode( type = 'FACE' )
|
height = radius1*2.0
|
||||||
bpy.ops.mesh.select_all( action = 'SELECT' )
|
vert.co.y = vert.co.y*0.03
|
||||||
bpy.ops.mesh.extrude_region_move(
|
vert.co.x = vert.co.x*0.1 + radius1/2.0
|
||||||
TRANSFORM_OT_translate={"value":(0, 0, 0.01)} )
|
theta = abs(vert.co.z/height)
|
||||||
bpy.ops.mesh.extrude_region_shrink_fatten(
|
vert.co.x = vert.co.x + 2.0*radius1*math.sin(theta)
|
||||||
TRANSFORM_OT_shrink_fatten={"value":-0.05})
|
vert.co.z = vert.co.z + 1.0*radius1
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
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):
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
shape = "pendant"
|
shape = "mesh"
|
||||||
output = "test"
|
output = "test"
|
||||||
|
|
||||||
if not os.path.exists(os.getcwd() + "/" + output):
|
if not os.path.exists(os.getcwd() + "/" + output):
|
||||||
os.makedirs(os.getcwd() + "/" + output)
|
os.makedirs(os.getcwd() + "/" + output)
|
||||||
|
|
||||||
height = 1.5
|
height = 1.5
|
||||||
radius = 0.5
|
radius = 0.8
|
||||||
color = [0.1, 0.1, 0.1]
|
color = [0.1, 0.1, 0.1]
|
||||||
|
|
||||||
product_gen.generate_product.generate(shape, height, radius, color, output)
|
product_gen.generate_product.generate(shape, height, radius, color, output)
|
||||||
|
|
Loading…
Reference in a new issue