This commit is contained in:
jmsgrogan 2017-10-23 14:37:12 +01:00
parent ea2435a159
commit a1e22c9f2b
13 changed files with 101 additions and 58 deletions

View file

@ -3,18 +3,7 @@ import bpy
import product_gen.generate_lamp_base import product_gen.generate_lamp_base
import product_gen.generate_shades import product_gen.generate_shades
def generate(shape, def generate_models(shape, height, radius):
height,
radius,
color,
output_prefix,
is_final=False):
prefix = os.getcwd() + "/" + output_prefix + "/" + output_prefix
# Set up scene
objs = bpy.data.objects
objs.remove(objs["Cube"], True)
# Shade # Shade
radius2 = 0.3 radius2 = 0.3
@ -27,7 +16,6 @@ def generate(shape,
elif shape == "bio": elif shape == "bio":
shade = product_gen.generate_shades.generate_bio_shade(radius, shade = product_gen.generate_shades.generate_bio_shade(radius,
radius2, height) radius2, height)
# Base # Base
radius1 = 0.3 radius1 = 0.3
radius2 = 0.2 radius2 = 0.2
@ -44,10 +32,12 @@ def generate(shape,
chord = product_gen.generate_lamp_base.generate_chord(height, chord = product_gen.generate_lamp_base.generate_chord(height,
radius, radius,
location) location)
models = {shade.name: shade, models = {shade.name: shade,
chord.name: chord, chord.name: chord,
base.name: base} base.name: base}
return models
def optimize_for_render(models):
# Smooth shapes # Smooth shapes
for eachModel in models.values(): for eachModel in models.values():
@ -55,11 +45,7 @@ def generate(shape,
for poly in bpy.context.object.data.polygons: for poly in bpy.context.object.data.polygons:
poly.use_smooth = True poly.use_smooth = True
# Set up materials and textures def apply_textures(colormap, models):
# Get material
colormap = {"shade": color,
"base": (220.0/255.0, 220.0/255.0, 220.0/255.0),
"chord": (20.0/255.0, 20.0/255.0, 20.0/255.0)}
for eachName in colormap.keys(): for eachName in colormap.keys():
mat = bpy.data.materials.get(eachName + "-material") mat = bpy.data.materials.get(eachName + "-material")
@ -81,31 +67,4 @@ def generate(shape,
bpy.context.active_object.data.materials[0] = mat bpy.context.active_object.data.materials[0] = mat
else: else:
# no slots # no slots
bpy.context.active_object.data.materials.append(mat) bpy.context.active_object.data.materials.append(mat)
# Set up world
bpy.context.scene.world.use_sky_paper = True
bpy.context.scene.world.horizon_color = (0.9, 0.9, 0.9)
#bpy.context.scene.world.light_settings.use_environment_light = True
# Set up lamps and cameras
objs["Lamp"].location = objs["Camera"].location
objs["Lamp"].delta_location = (-3, 0, -1)
# Set up and do the render
bpy.context.scene.render.resolution_x = 600.0
bpy.context.scene.render.resolution_percentage = 99.0
if is_final:
bpy.context.scene.render.filepath = prefix + "_kitchen.png"
bpy.ops.render.render(write_still=True)
bpy.context.scene.render.filepath = prefix + "_hall.png"
bpy.ops.render.render(write_still=True)
bpy.context.scene.render.filepath = prefix + "_landing.png"
bpy.ops.render.render(write_still=True)
else:
bpy.context.scene.render.filepath = prefix + ".png"
bpy.ops.render.render(write_still=True)

View file

@ -0,0 +1,46 @@
import os
import bpy
import product_gen.generate_lamp
import rendering.setup_scene
import rendering.setup_renderer
def generate(shape,
height,
radius,
color,
output_prefix,
is_final=False):
rendering.setup_scene.initialize_scene()
# Generate models
models = product_gen.generate_lamp.generate_models(shape, height, radius)
# Optimize geometries for render
product_gen.generate_lamp.optimize_for_render(models)
# Set up materials and textures
colormap = {"shade": color,
"base": (220.0/255.0, 220.0/255.0, 220.0/255.0),
"chord": (20.0/255.0, 20.0/255.0, 20.0/255.0)}
product_gen.generate_lamp.apply_textures(colormap, models)
rendering.setup_scene.setup_scene()
rendering.setup_renderer.setup_renderer()
# Do rendering
prefix = os.getcwd() + "/" + output_prefix + "/" + output_prefix
if is_final:
bpy.context.scene.render.filepath = prefix + "_kitchen.png"
bpy.ops.render.render(write_still=True)
bpy.context.scene.render.filepath = prefix + "_hall.png"
bpy.ops.render.render(write_still=True)
bpy.context.scene.render.filepath = prefix + "_landing.png"
bpy.ops.render.render(write_still=True)
else:
bpy.context.scene.render.filepath = prefix + ".png"
bpy.ops.render.render(write_still=True)

Binary file not shown.

View file

@ -0,0 +1,18 @@
import bpy
def setup_renderer(engine="CYCLES"):
# Set up and do the render
if engine=="CYCLES":
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.cycles.samples = 300.0
bpy.context.scene.cycles.caustics_reflective = False
bpy.context.scene.cycles.caustics_refractive = False
bpy.context.scene.cycles.max_bounces = 1000.0
bpy.data.scenes["Scene"].render.use_border = True # Tell Blender to use border render
bpy.data.scenes["Scene"].render.border_max_y = 0.75 # Set the border top at 3/4 of the image's height
bpy.data.scenes["Scene"].render.border_min_y = 0.33 # Set the border bottom at 1/3 of the image's height
bpy.data.scenes["Scene"].render.border_min_x = 0.25 # Set the border left at 1/4 of the image's width
bpy.data.scenes["Scene"].render.border_max_x = 0.65 # Set the border right at the image's right border
bpy.context.scene.render.resolution_x = 600.0
bpy.context.scene.render.resolution_percentage = 100.0

View file

@ -0,0 +1,20 @@
import bpy
def initialize_scene():
# Set up scene
objs = bpy.data.objects
objs.remove(objs["Cube"], True)
def setup_scene():
# Set up world
bpy.context.scene.world.use_sky_paper = True
bpy.context.scene.world.horizon_color = (0.95, 0.95, 0.95)
#bpy.context.scene.world.light_settings.use_environment_light = True
# Set up lamps and cameras
bpy.data.objects["Lamp"].location = bpy.data.objects["Camera"].location
bpy.data.objects["Lamp"].delta_location = (-3, 0, -3)
#bpy.data.objects["Lamp"].type = "POINT"
bpy.data.objects["Lamp"].name = "front"

View file

@ -2,7 +2,7 @@ import os
import sys import sys
import random import random
import json import json
import product_gen.generate_lamp import product_gen.generate_product
from argparse import ArgumentParser from argparse import ArgumentParser
@ -19,10 +19,10 @@ if __name__ == "__main__":
height = float(shape_params["height"]) height = float(shape_params["height"])
radius = float(shape_params["radius"]) radius = float(shape_params["radius"])
color = [random.random()*255.0, color = [random.random(),
random.random()*255.0, random.random(),
random.random()*255.0] random.random()]
product_gen.generate_lamp.generate(shape, height, radius, color, output) product_gen.generate_product.generate(shape, height, radius, color, output)
shape_parameters = shape_params shape_parameters = shape_params
shape_parameters["color"] = color shape_parameters["color"] = color

View file

@ -3,7 +3,7 @@ import ast
import sys import sys
import random import random
import json import json
import product_gen.generate_lamp import product_gen.generate_product
from argparse import ArgumentParser from argparse import ArgumentParser
@ -22,5 +22,5 @@ if __name__ == "__main__":
radius = float(shape_params["radius"]) radius = float(shape_params["radius"])
color = ast.literal_eval(shape_params["color"]) color = ast.literal_eval(shape_params["color"])
print(color[0]) print(color[0])
product_gen.generate_lamp.generate(shape, height, radius, product_gen.generate_product.generate(shape, height, radius,
color, output, is_final=True) color, output, is_final=True)

View file

@ -2,7 +2,7 @@ import os
import sys import sys
import random import random
import json import json
import product_gen.generate_lamp import product_gen.generate_product
from argparse import ArgumentParser from argparse import ArgumentParser
if __name__ == "__main__": if __name__ == "__main__":
@ -18,9 +18,9 @@ if __name__ == "__main__":
height = 1.0 + random.random()*1.5 height = 1.0 + random.random()*1.5
radius = 0.2 + random.random()*1.0 radius = 0.2 + random.random()*1.0
color = [18.0, 18.0, 18.0] color = [0.1, 0.1, 0.1]
product_gen.generate_lamp.generate(shape, height, radius, color, output) product_gen.generate_product.generate(shape, height, radius, color, output)
shape_parameters = {"shape": shape, shape_parameters = {"shape": shape,
"height": height, "height": height,

View file

@ -1 +1 @@
{"output": "test456", "radius": "1.0", "color": [154.90465134747797, 85.00668266837187, 234.34599434969277], "height": "1.0", "shape": "cone"} {"color": [0.2536788765243849, 0.7557341205824731, 0.6786201102941254], "shape": "cone", "height": "1.0", "radius": "1.0", "output": "test456"}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 57 KiB