Mathness on DeviantArthttps://www.deviantart.com/mathness/art/20170405-673119448Mathness

Deviation Actions

Mathness's avatar

20170405

By
Published:
267 Views

Description

Finally moved the experimental X branch of my render into the main branch, Linux and OpenCL support got nuked for now. It is another complete rewrite using what I have learned so far. Fully modular, so easier to extend and maintain. Also got a file parser, so no need to recompile every time I want to tweak a render (about time really, no need for special cases and other ugly hacks :blush:). It is still missing a few things to be feature complete. The code can almost be called beautiful.

This render would be impossible in my old render, as the bright light source is a tiny sphere just outside the frame. Download for a full view of the render.

I have been pondering where to take my render engine next, besides moving beyond unidirectional path tracing. I have considered either writing a GUI for it and my various mesh generators, or writing it as add-ons/plug-ins for existing software. For now I am doing it as an add-on, as it seems the simplest (on Windows). So I have been poking around Blender and made a simple add-on, which was used to make the object in this render, it uses a truncated icosahedron as the base. Probably not the best way to do this, but it works (at least for me :slow:) in Blender 2.78, simply copy the code below into a file called PolygonPoke.py and install it through the user preferences (remember to enable it), it can be found in the object menu (at the top for me) when in object mode.

Enjoy. :)


bl_info = {
    "name": "PolygonPoke" ,
    "category": "Object"
}

import bpy
import bmesh

class ObjectPolygonPoke( bpy.types.Operator ) :
    """Object Polygon Poke"""
    bl_idname = "object.polygon_poke"
    bl_label = "Polygon Poke"
    bl_options = { 'REGISTER' , 'UNDO' }

    # Add a scalar user can change. TODO remove limit?
    scale = bpy.props.FloatProperty( name = "Scale" , default = 1.0 , min = -10.0 , max  = 10.0 )

    # Blender hook
    def execute( self , context ) :
        work_mesh = bmesh.new() # Create empty mesh container.
        work_mesh.from_mesh( bpy.context.object.data ) # Copy selected mesh.

        new_mesh = bmesh.new() # Create empty mesh container.

        # Loop over all polygons in work_mesh
        for polygon in work_mesh.faces :
            normal = polygon.normal

            # Find the centre of the polygon, then scale along the normal.
            centre = polygon.calc_center_bounds()
            centre = new_mesh.verts.new( centre + normal * self.scale )

            num_elem = len( polygon.verts ) # Number of elements in the polygon.

            # Create new polygons from vertex1, vertex2 and centre
            for index in range( 0 , num_elem ) :
                vertex1 = new_mesh.verts.new( polygon.verts[ index ].co ) # Get vertex coordinates
                vertex2 = new_mesh.verts.new( polygon.verts[ ( index + 1 ) % num_elem ].co )
                new_mesh.faces.new( ( vertex1 , vertex2 , centre ) )

        # TODO vertex clean up, dublicates are created
        new_mesh.to_mesh( bpy.context.object.data ) # Replace the selected mesh with new_mesh.
        work_mesh.free() # Clear memory.
        new_mesh.free() # Clear memory.

        # Let Blender know all is done
        return {'FINISHED'}

def menu_func( self , context ) :
    self.layout.operator( ObjectPolygonPoke.bl_idname )
   
def register() :
    bpy.utils.register_class( ObjectPolygonPoke )
    bpy.types.VIEW3D_MT_object.append( menu_func )

def unregister() :
    bpy.utils.unregister_class( ObjectPolygonPoke )
    bpy.types.VIEW3D_MT_object.remove( menu_func )

if __name__ == "__main__" :
    register()
Image size
2560x1440px 2.99 MB
© 2017 - 2024 Mathness
Comments2
Join the community to add your comment. Already a deviant? Log In
ahmadasaad89's avatar