<div class="gmail_quote">Hello,<br><br>On Thu, Jul 19, 2012 at 11:49 PM, Maltzan, Christopher <span dir="ltr"><<a href="mailto:maltzanc@garnet.union.edu" target="_blank">maltzanc@garnet.union.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I am writing to you now to ask specifically about advice or comments on on connecting my software (genetic algorithm and GUI) to blender which would then make relatively simple changes to a base model and then send renders back to my software. In my mind, the hardest part is teaching blender to make changes to the avatar. Do you have any advice for where I can start?</blockquote>
<div><br>That depends on the level of integration you want. If you want loose coupling, I would suggest to use a client/server architecture, keeping Blender as the server. You can use my code as base for your server script:<br>
<font size="1"><br></font><font face="courier new,monospace" size="1">#!/usr/bin/env python3<br>#-*- coding:utf-8 -*-<br><br>import socketserver<br>from ctypes import Structure, c_byte, c_float, c_int, sizeof<br><br>import bpy<br>
from mathutils import Euler<br><br><br>HOST, PORT = "0.0.0.0", 9999<br><br><br>def get_list(s):<br>    llen = ord(s.recv(1))<br>    retv = []<br>    for i in range(llen):<br>        slen = ord(s.recv(1))<br>        retv.append(s.recv(slen).decode("ascii"))<br>
    return retv<br><br><br>class EyeParameters(Structure):<br>     _fields_ = [ <br>        ('eye', c_byte),<br>        ('retina', c_byte),<br>        ('yaw', c_float),<br>        ('pitch', c_float),<br>
        ('aperture', c_float),<br>        ('distance', c_float),<br>        ('samples', c_int),<br>        ('format', c_int),<br>        ]<br><br><br>class EyeClientHandler(socketserver.BaseRequestHandler):<br>
    def handle(self):<br>        print("New client {}.".format(self.client_address))<br>        socket = self.request.fileno()<br>        self.request.sendall(b"EyeServer")<br>        if self.request.recv(9) != b"EyeClient":<br>
            print("Bad request, closed.")<br>            return<br>        cams, retinas = (get_list(self.request) for i in range(2))<br>        print(cams)<br>        print(retinas)<br>        e = EyeParameters()<br>
        while True:<br>            if self.request.recv_into(e) != sizeof(e):<br>                print("Client closed the connection.")<br>                break<br>            if e.eye == -1 or e.eye == 0xff:<br>
                print(e.eye)<br>                print("Client requested server termination.")<br>                EyeServer.quit = True<br>                break<br><br>            cam = bpy.data.objects[cams[e.eye]]<br>
            bpy.context.scene.camera = cam<br>            bpy.context.scene.cycles.samples = e.samples<br>            bpy.context.scene.cycles.seed += 1<br>            cam.rotation_euler = Euler((e.yaw, e.pitch, 0))<br>            cam.data.dof_distance = e.distance<br>
            cam.data.cycles.aperture_size = e.aperture<br>            cam.data.cycles.retina = retinas[e.retina]<br>            cam.data.cycles.retina_socket = socket | (e.format << 16)<br>            bpy.ops.render.render()<br>
<br><br>class EyeServer:<br>    quit = False<br>    server = socketserver.TCPServer((HOST, PORT), EyeClientHandler)<br>    @classmethod<br>    def serve(self):<br>        while not self.quit:<br>            self.server.handle_request()<br>
<br>try:<br>    EyeServer.serve()<br>except KeyboardInterrupt:<br>    print("EyeServer will shutdown now.")<br></font><br><br>Notes:<br><ul><li>this is only an example, you will not be able to run it (it requires some modifications I made to Cycles to render mimicking the photoreceptors in the retina)</li>
<li>I'll not provide the client code because: 1 - it is easy to infer; 2 - it is currently a C++ spaghetti code; 3 - it is not using Boost, but some old networking code I made ages ago<br></li><li>the transmission is binary, ctypes does all the magic implicitly</li>
<li>I don't do anything  after <span style="font-family:courier new,monospace">render()</span> because my Cycles patch transmits the results of the render through the socket, but you could save the rendered image to a file and then open it and send its contents</li>
<li>sorry for the lack of comments, but I think it is pretty easy to understand this code... if you have any question, just ask<br></li></ul> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div><br></div><div>My idea was that I would make a plugin which could select pre-determined vertices and move them on the xyz grid to specific pre-programmed coordinates or select a group of vertices and then scale them to be slightly larger (to make an avatar have the trait of thick arms for example). Obviously an over-simplification, but you get the idea. I will of course make the software open to the community :)</div>
</blockquote><div><br>If that is the case, I would recommend a collaboration with the Make Human folks... they have 90% of what you need already done.<br><br>Cheers,<br><br>Daniel<br></div></div><br>