~osomon/phatch/extract-all-metadata

« back to all changes in this revision

Viewing changes to data/blender/object.py

  • Committer: spe.stani.be at gmail
  • Date: 2009-09-15 19:55:39 UTC
  • mfrom: (1176.1.88 phatch-blender)
  • Revision ID: spe.stani.be@gmail.com-20090915195539-dpmhmaovmqljj695
updated blender action

Show diffs side-by-side

added added

removed removed

Lines of Context:
306
306
    name = 'Box'
307
307
 
308
308
    def set_up(self, args, image):
309
 
        ob = Object.Get(self.name)
 
309
        self._set_color(args)
 
310
        self._adapt_proportions(args, image)
310
311
 
311
 
        #box color
 
312
    def _set_color(self, args):
312
313
        box_material = Material.Get('box')
313
314
        box_material.setRGBCol(args['box_color'])
314
 
        #adapt proportions of box
 
315
 
 
316
    def _adapt_proportions(self, args, image):
 
317
        ob = Object.Get(self.name).getParent()
 
318
 
315
319
        width, height = image.getSize()
316
320
        fac = height/0.8
317
321
        box_width = width/fac
451
455
class ScaleModel(Mode):
452
456
    name = 'Scale Model'
453
457
 
 
458
    def execute(self, input_image_path, blender_object):
 
459
        im = Image.Load(input_image_path)
 
460
 
 
461
        im_width, im_height = im.getSize()
 
462
        im_size_ratio = im_width / im_height
 
463
 
 
464
        tex_width = blender_object.texface.width
 
465
        tex_height = blender_object.texface.height
 
466
        tex_size_ratio = tex_width / tex_height
 
467
 
 
468
        ob = Object.Get(blender_object.name).getParent()
 
469
        if tex_size_ratio > im_size_ratio:
 
470
            # scale width
 
471
            scaling_ratio = im_size_ratio / tex_size_ratio
 
472
            ob.SizeY *= scaling_ratio
 
473
        else:
 
474
            # scale height
 
475
            scaling_ratio = tex_size_ratio / im_size_ratio
 
476
            ob.SizeZ *= scaling_ratio
 
477
 
 
478
        return im
 
479
 
454
480
 
455
481
class BlenderInitializer:
456
482
    blender_objects = BlenderObjects()