Exporting Blender Animation to Flash Vector

(Kajenx) #1

Hey, I’m new here (and to blender), so I hope this into one of those questions that floods the forums everyday.

Anyway, as the title says, I want to export to the 2D .fla or .swf vector format for I can manipulate it for Flash video games. I’ve see a few python scripts that seem to be able to do this (sflender and VRM) but sflender doesn’t look like it’s been updated for a long time, and VRM exports to SVG…

Is there anyone out there who has been able to successfully use either of these scripts (or a newer one) with Blender 2.45 and Flash? Or should I try to find a version of Blender 2.36 and use it with sflender? Also, how do I get python scripts to work in Blender? I used to use scripts in Gmax when I was modeling for Warcraft III, but that was a bit different. I’ve never worked with python before so I’m pretty lost. :eek:

Thanks,
Luke

0 Likes

(enhzflep) #2

Hey Luke, welcome.

I’m afraid I can’t help you with regards to the whole flash issue, though I can shed a little light on the whole python issue. I managed to find a tute that talks you through creating your first script & found it to be quite good. It’s right here->http://www.blender.org/documentation/htmlI/c11087.html#BSG.PYT.L.S68.001
Something I will point out, is that you cannot change the indenting to suit your personal style - I tried to set it out the way I would program things normally and found that it wouldn’t run properly, on a account of the fact that blocks of code are identified by the amount they’re indented, my loops just weren’t running and I couldn’t figure out why - most frustrating.

After doing that tute, I got the bug and decided to write a script that would create the nose-cone of some model rockets I used to fly. Been wanting a script that would do it for years. What the script actually accomplishes isn’t so important as the way it goes about it. Perhaps you’ll find some use in it.

As for how to run them, the script in the tute may be saved anywhere. You then access and run it by opening up a TextEditor window in Blender, locate and load up your script then hit Alt-P.

For the one below, copy it to your blender scripts directory - on my linux pc, this is /home/enhzflep/.blender/scripts. (It’s somewhere under “Documents And Settings” on a windows PC.) Then open Blender and it should now appear in the menu under Add->Mesh->Ogive Rocket Nose.

That should be enough to get you started, there’s many, many resources around the net - you’re sure to find enough to get going. (Don’t frget you can look in the scripts directory at some of the bundled scripts for hints too)

Simon



#!BPY

""" Registration info for Blender menus
Name: 'Ogive Rocket Nose'
Blender: 240
Group: 'AddMesh'
Tip: 'Creates rocket nose cone that takes the Ogive shape'
"""

# OgiveNoseCone.py - simple script to create an Ogive shaped nose cone
#
# This was just something I had to have when modelling my model rockets.
# Proably could've found one if I looked, but that'd just kill 1/2 of
# the fun.
#
# 14 Aug 2007 - enhzflep -- simon beeching --



import Blender
from Blender import NMesh
from Blender.BGL import *
from Blender.Draw import *

import math
from math import *
    
                
def main():
        # Define numeric inputs used for tool 
        # these are the defaults when the tool is started
        numSidesInput = Blender.Draw.Create(8)
        diamInput = Blender.Draw.Create(1.0)
        lengthInput = Blender.Draw.Create(3.0)
        sectionsInput = Blender.Draw.Create(4)

        # array for popup window's content
        block = []
        
        #add input to array with title, min/max values & tool-tip
        block.append(("Sides: ", numSidesInput, 3, 40, "Number of sides that make up the nose-cone"))
        block.append(("Sections: ", sectionsInput, 1, 10, "Number of sections length-wise for nose-cone"))
        block.append(("Length: ", lengthInput, 0.01, 100, "Length of the nose-cone"))
        block.append(("Diameter: ", diamInput, 0.01, 100, "Diameter of the nose-cone"))
        
        #draw popup if it is not already shown
        if not Blender.Draw.PupBlock("Ogive Cone Creator", block):
            return
        
        # okay, controls defined and shown - lets create the object
        NoseCone(numSidesInput.val, sectionsInput.val,
                          lengthInput.val, diamInput.val)


#############################################################################
# NoseCone - function used to create an object shaped like an Ogive
#             nose-cone, as found on the front of rockets
#            Basically, this is just a cylinder creation function
#            that uses multiple sections, each with a different radius
#############################################################################
def NoseCone(numSides, sections, length, diam):
    curRing = 0
    curRadius = 0.0
    sectionStep = length / sections
    
    # add all of the circumference vertices
    poly = NMesh.GetRaw()
    for curRing in range(0, sections):
            curX = curRing * sectionStep
            curRadius = HardRadius(diam, length, curX)
            for i in range(0, numSides):
                phi = 3.141592653589 * 2 * i / numSides
                x = curRadius * cos(phi)
                y = curRadius * sin(phi)
                v = NMesh.Vert(x, y, curX)
                poly.verts.append(v)
    # add the vertex that is at the tip of the cone
    v = NMesh.Vert(0.0, 0.0, length)
    poly.verts.append(v)


    ######## Connects the vertices to form faces ########
    ## this block forms all of the faces that don't
    ## touch the tip vertex - these are all 4-sided
    for curSection in range(0, sections-1):
        offset = curSection * numSides
        for i in range(0, numSides):
            f = NMesh.Face()
             f.v.append(poly.verts[offset + i])                        # first circumference vertex
             f.v.append(poly.verts[offset + ((i+1)%numSides)])        # seconds circumference vertex
             f.v.append(poly.verts[offset + numSides+((i+1)%numSides)])    # third circumference vertex (second end)
             f.v.append(poly.verts[offset + i + numSides])
             poly.faces.append(f)

    ## this block forms all of the faces that are connected
    ## to the vertex at the tip - these are all 3-sided
    commonVert = (numSides*sections)         # offset into vertex array of the last vertex
    offset = (sections-1) * numSides        # number of vertices in the array before the one we're concerned with
    for i in range(0, numSides):
        f = NMesh.Face()
        f.v.append( poly.verts[commonVert])
        f.v.append( poly.verts[i + offset])
         f.v.append( poly.verts[ ((i+1)%numSides) + offset])
        poly.faces.append(f)

    polyObj = NMesh.PutRaw(poly)
    Blender.Redraw()

        

############################################################################
# SimpleRadius - function used to calculate an approximation for an
#                 ogive shaped nose-cone as found on the front of rockets
#
#                This approximation is somewhat 'flatter' than the one 
#                provided by the function HardRadius
############################################################################
def SimpleRadius(diam, length, curX):
    caliber = length / diam
    radius = (diam / 2) - ( (curX*curX) / (2*length*caliber) )
    return radius

############################################################################
# HardRadius - function used to calculate an approximation for an
#             ogive shaped nose-cone as found on the front of rockets
#             This function gives alomst identical results to the one
#             shown above, but is much expensive to calculate
############################################################################
def HardRadius(diam, length, curX):
    caliber = length / diam
    radius = diam * (pow(caliber,2) + 0.25)
    radius = pow(radius, 2)
    radius -= pow(curX, 2)
    radius = sqrt(radius)
    radius -= diam * (pow(caliber,2) - 0.25)
    return radius

#let's call main
main()
0 Likes

(Kajenx) #3

Hey, thanks for the help with the scripts. I got the VRM script to work for me, but I’m still unable to convert to swf from svg…

I suppose I could try learning python, but I doubt I could make a converter any time soon. I’m not much of a programmer…

Perhaps you could help me out, though. I found a converter at this site: http://robla.net/1996/svg2swf/

but I have no idea how to implement it. It says I need SAX and the Ming library to make it work. I tried downloading the files they said, but they basically just unzip a load of junk and I have no idea how to install them to make the script work.

Anyway, if you can make any sense out of it, I’d really appreciate it. I feel like I’m oh so close, yet oh so far…

0 Likes

(Atom) #4

You don’t really need to convert to SWF. Just render out your game elements in Blender as PNG files with alpha and then import them into the flash library. Put each element on stage and trace them. That will convert them to vector. It is under the Modify menu. modify/Bitmap/Trace Bitmap

0 Likes