PDA

View Full Version : [WIP/Experiment] X's - SketchUp to Blender Armature Creator - I need help (Post #5)


X Enterprises
05-18-2009, 06:33 PM
Okay, so I know that my two programs have been kind of a flop.:(


But I had a brilliant idea the other day:

Make it easier to add the armature to Blender and to assign groups to bones in the armature.

I've already created the export plugin for SketchUp. It gets all of the bones in the scene with a name starting with "bone_blend_" and gets their positions. The name of the bone comes after "bone_blend_" and after that comes the parent to that bone. If the bone doesn't have a perent you use "NOPARENT." After that comes the mesh to assign the bone to. And if there is no mesh to assign to then you use "NOMESH."

So, for example, a bone name could be this: "bone_blend_bone01_NOPARENT_NOMESH"

http://i204.photobucket.com/albums/bb63/xavier0794/brcta.jpg
^Here's a pic.:D

So, as I said the SketchUp exporter is finished.

Now I just have to make the Python plugin for Blender. I already started and I found the part I need in the API to add an armature and make vertex groups.


What do you guys think?

TheChicosAStar
05-18-2009, 07:17 PM
Great, how about others too?
Like curves, ect...

Viscosity086
05-18-2009, 10:01 PM
That would make it SOOO much easier! Belgabor's NLA Bake plugin to make the bone's and time segments kinda sucks would this be able to replace this at some point too? Make it kinda more straight forward?

SPACEMTNMAN
05-19-2009, 07:31 AM
Is this the thing you mentioned to me a while back in PM, It looks VERY useful :)

X Enterprises
06-11-2009, 04:56 PM
TheChicosAStar: The question is confusing. Could you reword it?

Viscosity086: I don't know if it could replace it in the future. *shrug*

SPACEMTNMAN: Actually no. The thing I mentioned to you in that PM is already a program. (Unfortunately, an unreleased one.:()


Anyway, I know it's been a while. But I've hit a snag. I have the whole Python script made. So it parses the file, and add the armature, but it doesn't add the child bones. I have all the code to add them, but it just doesn't add them, just the armature.

Here's the code:
###############################
#
# X's Blender BRCTA Importer
#
###############################
# This script imports *.brcta files into Blender from
# SketchUp and adds an armature to the scene. It
# also, if applicible, automatticaly assigns bones to
# the meshes in the scene.
###############################
#!BPY
"""
Name: 'BRCTA File (*.brcta)'
Blender: 247
Group: 'Import'
Tooltip: 'Import a BRCTA file'
"""
###############################
# Importing modules
###############################
import bpy

import Blender
from Blender import Mesh
from Blender import NMesh
from Blender import Window
from Blender import Armature
from Blender import Scene
from Blender import Mathutils
from Blender.BGL import *
from Blender.Draw import *

import math
from math import *

# Parameters
T_AddMeshTogg = Create(0)
T_Radius = Create(1.0)

# Events
EVENT_NOEVENT = 1
EVENT_DRAW = 2
EVENT_EXIT = 3

###############################
# GUI drawing
###############################
def draw():
global T_AddMeshTogg
global T_Radius
global EVENT_NOEVENT,EVENT_DRAW,EVENT_EXIT

########## Titles
glClear(GL_COLOR_BUFFER_BIT)
glRasterPos2d(8, 63)
Text("Import BRCTA Into Blender Script")

######### Parameters GUI Buttons
T_AddMeshTogg = Toggle("Assign Meshes to Bones", EVENT_NOEVENT, 10, 35, 210, 18, T_AddMeshTogg.val, "Wether or not to assign meshes to the bones");

######### Import and Exit Buttons
Button("Import",EVENT_DRAW , 10, 10, 80, 18)
Button("Exit",EVENT_EXIT , 140, 10, 80, 18)

def event(evt, val):
if (evt == QKEY and not val):
Exit()

def bevent(evt):
global EVENT_NOEVENT,EVENT_DRAW,EVENT_ADDMESHTOGGLE,EVENT_EXIT

######### Manages GUI events
if (evt == EVENT_EXIT):
Exit()
elif (evt== EVENT_DRAW):
Blender.Window.FileSelector(ProcessBRCTA, "Import")

Register(draw, event, bevent)

###############################
# Main Body
###############################
def ProcessBRCTA(file):
global T_AddMeshTogg

list_boneText = []
list_bonePosText = []
###########
# Read the file
###########
f = open(file,'r')
line = f.readline()

print "-Read BRCTA File-"

inHead=0

while line != '':
if inHead==0:
if "BRCTA Blender RCT Armature File :: File Version 0.1" in line:
inHead=1
if inHead==2:
line = line.replace("bone_blend_","")
line = line.replace("\n","")
strlist = line.split(" | ")
list_boneText.append(strlist[0])
list_bonePosText.append(strlist[-1])
line = f.readline()

inHead=2

f.close

print " Parse File"

###########
# Remove excess
###########
list_boneText.pop(0)
list_bonePosText.pop(0)

print " Perform cleanup of primary arrays"

###########
# Count array length
###########
len = 0
for item in list_boneText:
len += 1

print " Begin armature creation"
print " -- Creating armature"

###########
# Create armature
###########
arm = Armature.New('Armature.001')
arm.name = 'Armature.001'
arm.vertexGroups = True
arm.makeEditable()

scn = Scene.GetCurrent()

print " -- Create bone structure"

mxind = 0
prevpos = Mathutils.Vector([0,0,0])
makeVertexGroups = T_AddMeshTogg.val

for item in list_boneText:
params = item.split('_')
ind = list_boneText.index(item)
pos = list_bonePosText[ind].split(',')
print " -- -- Read bone from list: " + params[0]
print " -- -- Create bone: " + params[0] + ", at: " + list_bonePosText[ind]
eb = Armature.Editbone()
if mxind == 0:
eb.tail = Mathutils.Vector([0,0,0])
eb.roll = 10
eb.head = Mathutils.Vector([pos[0],pos[1],pos[2]])
prevpos = eb.head
eb.options = [Armature.HINGE]
arm.bones[params[0]] = eb
mxind += 1
if makeVertexGroups == True:
if params[2] != "NOMESH":
print " -- -- Create vertex group for: " + params[0] + ", to the mesh: " + params[2]
object = Blender.Object.Get(params[2])
objData = object.getData(mesh=1)

#Create list of verticies
listv = []
#Add mesh verticies to list
for v in objData.verts:
x=v.co.x
y=v.co.y
z=v.co.z
vect=Mathutils.Vector([x,y,z])
listv.append(vect)

#Apply vertex group
replace = Blender.Mesh.AssignModes.REPLACE
objData.addVertGroup(params[0])
objData.assignVertsToGroup(params[0], listv, 1, replace)

print " -- -- Make " + params[2] + " a child of the armature"
#Make armature parent
arm.makeParentDeform(object, 0, 0)
else:
eb.tail = prevpos
eb.roll = 10
eb.head = Mathutils.Vector([pos[0],pos[1],pos[2]])
prevpos = eb.head
eb.parent = arm.bones[params[1]]
eb.options = [Armature.HINGE, Armature.CONNECTED]
arm.bones[params[0]] = eb
if makeVertexGroups == True:
if params[2] != "NOMESH":
print " -- -- Create vertex group for: " + params[0] + ", to the mesh: " + params[2]
scn = Scene.GetCurrent()
object = Blender.Object.Get(params[2])
objData = object.getData(mesh=1)

#Create list of verticies
listv = []
#Add mesh verticies to list
for v in objData.verts:
listv.append(v.co)

#Apply vertex group
replace = Blender.Mesh.AssignModes.REPLACE
objData.addVertGroup(params[0])
objData.assignVertsToGroup(params[0], listv, 1, replace)

print " -- -- Make " + params[2] + " a child of the armature"
#Make armature parent
arm.makeParentDeform(object, 0, 0)

print " -- Updating scene"

scn.objects.new(arm)

print " Finish armature creation"

Blender.Redraw()Can anyone help?

TheChicosAStar
06-11-2009, 06:56 PM
hmmm.
Okay perhaps just an idea. Blender also has Beizer Curves, among other things. Perhaps those could be a possibility too?

coasterfreak
06-14-2009, 09:37 AM
This is great. Will we still have to use the OVL Maker, and the MXL Make, or can we just import our model from Sketchup like normal? Would there be time to make a step-by-step tutorial on how to use these programs? It would be appreciated by alot of us out here that want to make a CFR, that just dont understand the tutorials that are already out there. me, i make CS, but yet i dont understand how to use your programs yet. (im not all that savee about programs like that) a please and thank you, would be and will be givin to you, if you could. Thanks in advanced....