Skip to content

Instantly share code, notes, and snippets.

@yamahigashi
Created September 20, 2012 06:37
Show Gist options
  • Save yamahigashi/3754282 to your computer and use it in GitHub Desktop.
Save yamahigashi/3754282 to your computer and use it in GitHub Desktop.
export DoraSkin's dsw file from softimage
def export_dora_skin(path, objects=Application.Selection):
'''DoraSkin 形式でエンベロープウェイトをはきだす'''
import gear
import gear.xsi.operator as ope
# ------------------------------------------------------------------------
for obj in objects:
# object validation, having envelope
envelope_op = ope.getOperatorFromStack(obj, "envelopop")
if not envelope_op:
gear.log("%s has no envelope skipped" % obj.Name, gear.sev_warning)
continue
# ヘッダ
deformers = envelope_op.Deformers
header = "DoraYuki Skin Weight Format 3.00"
defs = ",".join([x.Name for x in deformers])
# 頂点ごとの3点セット ウェイト、ポジション、UV
pos_str = lambda x: str(x.Position.X) + "," \
+ str(x.Position.Y) + "," \
+ str(x.Position.Z)
weights = [[float(y) / 100.0 for y in x] for x in envelope_op.Weights]
points = obj.ActivePrimitive.Geometry.Points
positions = map(pos_str, points)
#uvs = [] # currentry not supported
res = map((lambda x, y:
str(x).replace("[", "").replace("]", "|") + y + "|0.5,0.5"),
weights, positions)
res = "\n".join(res)
res = "\n".join([header, defs, res])
# --------------------------------------------------------------------
# Save to file each objects
#FIXME:not warn overritten and not error handling
f = open(os.path.join(path, obj.Name + '.dsw'), 'w')
f.write(res)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment