# HG changeset patch
# User tkaito@nw0534.st.ie.u-ryukyu.ac.jp
# Date 1228980819 -32400
# Node ID 17f2138b9d527af2f21d9951613ed74bf8de3145
# Parent 5a4f2497c22d51548c59e8694adac0e1dbf53a82
Scale-SceneGraph.cpp
diff -r 5a4f2497c22d -r 17f2138b9d52 SceneGraph/BlenderScript/export_xml1209.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SceneGraph/BlenderScript/export_xml1209.py Thu Dec 11 16:33:39 2008 +0900
@@ -0,0 +1,457 @@
+#!BPY
+"""Registration info for Blender menus:
+Name: 'Libps3 (.xml)'
+Blender: 240
+Group: 'Export'
+Tooltip: 'Export to (.xml) for libps3'
+"""
+
+
+######################################################
+# Importing modules
+######################################################
+
+import math
+#import subprocess
+import os
+import Blender
+import struct
+import base64
+from Blender import NMesh, Scene, Object, Material, Texture, Window
+from Blender import sys as bsys, Mathutils, Draw, BGL
+from Blender.sys import *
+
+
+def info(object, spacing=10, collapse=1):
+ """Print methods and doc strings.
+
+ Takes module, class, list, dictionary, or string."""
+ methodList = [e for e in dir(object) if callable(getattr(object, e))]
+ processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)
+ print "\n".join(["%s %s" %
+ (method.ljust(spacing),
+ processFunc(str(getattr(object, method).__doc__)))
+ for method in methodList])
+
+
+######################################################
+# Data Structures
+######################################################
+
+
+
+
+######################################################
+# Functions
+######################################################
+
+# Image Get ?
+# New name based on old with a different extension
+def newFName(ext):
+ return Blender.Get('filename')[: -len(Blender.Get('filename').split('.', -1)[-1]) ] + ext
+
+
+#exporting an anime
+###change
+#def export_anime(object_name):
+def export_anime(object_name,file):
+ startF = Blender.Get('staframe')
+ endF = Blender.Get('endframe')
+ #str = ""
+ file.write("")
+ file.write("\t\t\n" %(endF) )
+ for i in range (startF, endF+1):
+ Blender.Set('curframe', i)
+ Blender.Redraw()
+ time1 = Blender.sys.time()
+
+ ##### XML header ######
+ #get all the objects in this scene
+ activelayers = Window.ViewLayer()
+ for i in range(len(activelayers)):
+ activelayers[i] = 2**(activelayers[i]-1)
+ object_list1 = Blender.Scene.GetCurrent().getChildren()
+ object_list = []
+ matnames= []
+ for obj in object_list1:
+ if obj.Layer in activelayers:
+ object_list.append(obj)
+
+ if obj.getType() == "Mesh":
+ materials_obj_list = []
+ materials_obj_list = obj.getData().materials
+ for mat in materials_obj_list:
+ if mat.name not in matnames:
+ matnames.append(mat.name)
+
+ ##### Process Meshes ######
+ for obj in object_list:
+ matrix = obj.getMatrix()
+ if obj == object_name:
+ file.write("\t\t\t%f %f %f\n" %(matrix[3][0], matrix[3][1], matrix[3][2]) )
+
+ file.write("\t\t\n")
+ #return str
+
+
+
+# exporting a mesh
+##change
+#def exportMesh(mesh, obj):
+def exportMesh(mesh, obj, file):
+
+ vdata = [] # list of [ii0, ii1, ii2, ...] lists indexed by Blender-Vertex-index
+ vlist = []
+ flist = []
+ tri_first = []
+ tri_second = []
+ tri_third = []
+
+ def addVertex(bvindex, coord, normal, uv):
+ index = -1
+ if bvindex < len(vdata):
+ for ivindex in vdata[bvindex]:
+ v = vlist[ivindex]
+ if (abs(v[0][0]-coord[0])<0.0001) and \
+ (abs(v[0][1]-coord[1])<0.0001) and \
+ (abs(v[0][2]-coord[2])<0.0001) and \
+ (abs(v[1][0]-normal[0])<0.0001) and \
+ (abs(v[1][1]-normal[1])<0.0001) and \
+ (abs(v[1][2]-normal[2])<0.0001):
+ if ((v[2]==[]) and (uv==[])) or \
+ ((abs(v[2][0]-uv[0])<0.0001) and \
+ (abs(v[2][1]-uv[1])<0.0001)):
+ index = ivindex
+ if index < 0:
+ index = len(vlist)
+ vlist.append([coord, normal, uv])
+ while bvindex >= len(vdata):
+ vdata.append([])
+ vdata[bvindex].append(index)
+ return index
+
+ def addFace(mindex, index0, index1, index2):
+ while mindex >= len(flist):
+ flist.append([])
+ flist[mindex].append([index0, index1, index2])
+
+ ###change
+ def getFaces():
+ ##change
+ #str = ""
+ file.write("")
+ matrix = obj.getMatrix()
+
+ for mindex in range(len(flist)):
+ fl = flist[mindex]
+ if fl != []:
+ parent_name = obj.getParent()
+ if parent_name:
+ parent_name = "%s" %parent_name
+ ###change
+ #str += "\t\n" %(obj.name, len(fl)*3, parent_name[8:-1])
+ file.write("\t\n" %(obj.name, len(fl)*3, parent_name[8:-1]) )
+ else:
+ ###change
+ #str += "\t\n" %(obj.name, len(fl)*3)
+ file.write("\t\n" %(obj.name, len(fl)*3) )
+ ###change
+ #str += "\t\t\n"
+ file.write("\t\t\n")
+ for f in fl:
+ tri_first = vlist[f[0]]
+ tri_second = vlist[f[1]]
+ tri_third = vlist[f[2]]
+
+ file.write("\t\t\t%f %f %f\n" %(tri_first[0][0] + matrix[3][0], tri_first[0][1] + matrix[3][1], tri_first[0][2] + matrix[3][2]) )
+ file.write("\t\t\t%f %f %f\n" %(tri_second[0][0] + matrix[3][0], tri_second[0][1] + matrix[3][1], tri_second[0][2] + matrix[3][2]) )
+ file.write("\t\t\t%f %f %f\n" %(tri_third[0][0] + matrix[3][0], tri_third[0][1] + matrix[3][1], tri_third[0][2] + matrix[3][2]) )
+ file.write("\t\t\n")
+
+ file.write("\t\t\n")
+ for f in fl:
+ tri_first = vlist[f[0]]
+ tri_second = vlist[f[1]]
+ tri_third = vlist[f[2]]
+
+ file.write("\t\t\t%f %f %f\n" %(tri_first[1][0], tri_first[1][1], tri_first[1][2]) )
+ file.write("\t\t\t%f %f %f\n" %(tri_second[1][0], tri_second[1][1], tri_second[1][2]) )
+ file.write("\t\t\t%f %f %f\n" %(tri_third[1][0], tri_third[1][1], tri_third[1][2]) )
+ file.write("\t\t\n" )
+
+ file.write("\t\t\n" )
+ ###parameter of translate
+ file.write("\t\t\t%f %f %f\n" % (matrix[3][0], matrix[3][1], matrix[3][2]) )
+ file.write("\t\t\n")
+
+ if tri_first[2] != []:
+ file.write("\t\t\n")
+ for f in fl:
+ tri_first = vlist[f[0]]
+ tri_second = vlist[f[1]]
+ tri_third = vlist[f[2]]
+
+ file.write("\t\t\t%f %f\n" %(tri_first[2][0], tri_first[2][1]) )
+ file.write("\t\t\t%f %f\n" %(tri_second[2][0], tri_second[2][1]) )
+ file.write("\t\t\t%f %f\n" %(tri_third[2][0], tri_third[2][1]) )
+ file.write("\t\t\n")
+ else:
+ file.write("\t\t\n")
+
+
+ ### get texture_image and change base64 data
+ texture = mesh.faces[0].image
+ if texture:
+ file.write("\t\t\n" %(texture.getName()) )
+ image_path = texture.getFilename()
+ #file.write("print_path = %s" %(image_path) )
+ input = open(expandpath(image_path), 'r')
+ #input = open('/Users/tkaito/CVS/Game_project/student/y06/e065725/SG_cube/xml/image_file/sample_white.png', 'r')
+ output = open('output.txt', 'w')
+ base64.encode(input,output)
+ input.close()
+ output.close()
+ input = open('output.txt', 'r')
+ for b64 in input.readlines():
+ file.write("\t\t\t%s" %b64)
+ input.close()
+ file.write("\t\t\n")
+ else:
+ file.write("\t\t\n" %("sample_white.png") )
+
+ file.write("\t\t\tiVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAAEElEQVQImWP8zwABTAwUMQBJQQEP\n");
+ file.write("\t\t\tlYH+agAAAABJRU5ErkJggg==\n");
+
+ file.write("\t\t\n")
+
+ #return str
+
+ vdata = []
+ vlist = []
+ flist = []
+ for face in mesh.faces:
+ iis = [-1, -1, -1, -1]
+ for vi in range(len(face.v)):
+ vert = face.v[vi]
+ if face.smooth:
+ normal = vert.no
+ else:
+ normal = face.no
+ if len(face.uv) == len(face.v):
+ uv = face.uv[vi]
+ else:
+ uv = []
+ iis[vi] = addVertex(vert.index, vert.co, normal, uv)
+ addFace(face.materialIndex, iis[0], iis[1], iis[2])
+ if len(face.v)==4:
+ addFace(face.materialIndex, iis[2], iis[3], iis[0])
+
+ #str = ""
+ #str += getFaces()
+ getFaces();
+
+ #return str
+
+
+######################################################
+# EXPORT
+######################################################
+def save_xml(filename, unindexedname, anim):
+ print("XML EXPORT\n")
+ time1 = Blender.sys.time()
+ print("Saving to '" + filename + "'...\n")
+ file = open(filename, 'w')
+
+ count_h = 0
+ n = 0
+ filename_h = filename[:-4] + ".h" #header file for cpp
+ file_h = open(filename_h, 'w')
+
+ ##### XML header ######
+ file.write("\n")
+
+ #get all the objects in this scene
+ activelayers = Window.ViewLayer()
+ for i in range(len(activelayers)):
+ activelayers[i] = 2**(activelayers[i]-1)
+ object_list1 = Blender.Scene.GetCurrent().getChildren()
+ object_list = []
+ matnames= []
+ for obj in object_list1:
+ if obj.Layer in activelayers:
+ object_list.append(obj)
+
+ if obj.getType() == "Mesh":
+ materials_obj_list = []
+ materials_obj_list = obj.getData().materials
+ for mat in materials_obj_list:
+ if mat.name not in matnames:
+ matnames.append(mat.name)
+
+ ##### Process Meshes ######
+ meshlist = []
+ file.write("\n")
+ for obj in object_list:
+ if obj.getType() == "Mesh":
+ objectname = obj.getName()
+ mesh = Blender.NMesh.GetRawFromObject(objectname)
+ meshname = mesh.name
+ meshlight = 0
+ if len(mesh.materials) > 0:
+ mat0 = mesh.materials[0]
+ if mat0.emit > 0:
+ meshlight = 1
+ if meshlight:
+ print "processing Object \"%s\" as Meshlight (Mesh \"%s\")..." %(objectname, meshname)
+ else:
+ print "processing Object \"%s\" (Mesh \"%s\")..." %(objectname, meshname)
+ try:
+ meshlist.index(meshname)
+ except ValueError:
+ ###change
+ #file.write(exportMesh(mesh,obj))
+ exportMesh(mesh,obj,file)
+ meshlist.append(meshname)
+ if anim == 1:
+ #file.write("\t\t\n")
+ ###change
+ #file.write(export_anime(obj))
+ export_anime(obj,file)
+ #file.write("\t\t\n")
+ file.write("\t\n")
+ file_h.write("#define %s scene_graph" %(obj.name))
+ while n != count_h:
+ file_h.write("->next")
+ n = n + 1
+ file_h.write("\n")
+ count_h = count_h + 1
+ n = 0
+
+
+ ##### XML FOOTER ######
+ file.write("")
+ file.close()
+ file_h.close()
+ print("Finished.\n")
+
+ time2 = Blender.sys.time()
+ print("Processing time: %f\n" %(time2-time1))
+ Draw.Exit()
+
+
+### SAVE ANIMATION ###
+def save_anim(filename):
+ global MatSaved
+
+ MatSaved = 0
+ unindexedname = filename
+ save_xml(filename, unindexedname, 1)
+
+
+#### SAVE STILL (hackish...) ####
+def save_still(filename):
+ global MatSaved
+
+ MatSaved = 0
+ unindexedname = filename
+ save_xml(filename, unindexedname, 0)
+
+######################################################
+# Settings GUI
+######################################################
+
+# Assign event numbers to buttons
+evtNoEvt = 0
+evtExport = 1
+evtExportAnim = 2
+
+# Set initial values of buttons
+
+## 800 600
+
+sceneSizeX = Scene.GetCurrent().getRenderingContext().imageSizeX()
+sceneSizeY = Scene.GetCurrent().getRenderingContext().imageSizeY()
+
+SizeX = Draw.Create(sceneSizeX)
+SizeY = Draw.Create(sceneSizeY)
+TexExponent = Draw.Create(2.3)
+
+## 1
+MLT = Draw.Create(1)
+
+## 0.1
+LMP = Draw.Create(0.1)
+
+## 0.02
+MaxChange = Draw.Create(0.02)
+
+## 0.7
+RRLP = Draw.Create(0.7)
+
+## 100
+MaxDepth = Draw.Create(100)
+
+## false
+Bidirectional = Draw.Create(0)
+
+## 14
+StrataWidth = Draw.Create(14)
+
+## 0
+Logging = Draw.Create(0)
+
+## false
+SaveUTMExr = Draw.Create(0)
+
+## false
+SaveTMExr = Draw.Create(0)
+
+## 0.0
+LensRadius = Draw.Create(0.0)
+
+## 2.0
+FocusDistance = Draw.Create(2.0)
+
+## 2.0
+Turbidity = Draw.Create(2.0)
+
+GroundPlane = Draw.Create(1)
+
+## Separate materials
+MatFile = Draw.Create(1)
+
+# text color fix
+textcol = [0, 0, 0]
+
+
+def gui():
+ global evtNoEvt, evtExport, evtExportAnim
+ global SizeX, SizeY, TexExponent, MLT, LMP, MaxChange, RRLP, MaxDepth, Bidirectional, StrataWidth, Logging, SaveUTMExr, SaveTMExr, LensRadius, FocusDistance,Turbidity, GroundPlane, MatFile
+ global textcol
+
+ Draw.Button("Export", evtExport, 10, 25, 100, 18, "Open file dialog and export")
+ Draw.Button("Export Animation", evtExportAnim, 130, 25, 150, 18, "Open filedialog and export animation (careful: takes a lot of diskspace!!!)")
+ BGL.glColor3f(textcol[0], textcol[1], textcol[2]) ; BGL.glRasterPos2i(10,10) ; Draw.Text("Press Q or ESC to quit.", "tiny")
+
+ BGL.glRasterPos2i(10,60) ; Draw.Text("xml exporter for libps3")
+
+
+def event(evt, val): # function that handles keyboard and mouse events
+ if evt == Draw.ESCKEY or evt == Draw.QKEY:
+ stop = Draw.PupMenu("OK?%t|Cancel export %x1")
+ if stop == 1:
+ Draw.Exit()
+ return
+
+def buttonEvt(evt): # function that handles button events
+ if evt == evtExport:
+ Blender.Window.FileSelector(save_still, "Export", newFName('xml'))
+ if evt == evtExportAnim:
+ Blender.Window.FileSelector(save_anim, "Export Animation", newFName('xml'))
+ #if there was an event, redraw the window
+ if evt:
+ Draw.Redraw()
+
+Draw.Register(gui, event, buttonEvt)
+
+
diff -r 5a4f2497c22d -r 17f2138b9d52 TaskManager/Test/test_render/Makefile.def
--- a/TaskManager/Test/test_render/Makefile.def Thu Dec 11 11:18:44 2008 +0900
+++ b/TaskManager/Test/test_render/Makefile.def Thu Dec 11 16:33:39 2008 +0900
@@ -7,6 +7,7 @@
# ex: linux/ps3
CERIUM = /home/gongo/Cerium
+#CERIUM = /Users/tkaito/hg/Game/Cerium
#CERIUM = ../../..
diff -r 5a4f2497c22d -r 17f2138b9d52 TaskManager/Test/test_render/SceneGraph.cpp
--- a/TaskManager/Test/test_render/SceneGraph.cpp Thu Dec 11 11:18:44 2008 +0900
+++ b/TaskManager/Test/test_render/SceneGraph.cpp Thu Dec 11 16:33:39 2008 +0900
@@ -323,7 +323,11 @@
texture_image = converted;
}
- uint32 *tex_dest = (uint32*)manager->malloc(texture_image->w*texture_image->h*4);
+ int image_tmp = texture_image->w*texture_image->h*4;
+ int tile_size = image_tmp + image_tmp/2 + image_tmp/4 + image_tmp/8 + image_tmp/16;
+ //uint32 *tex_dest = (uint32*)manager->malloc(texture_image->w*texture_image->h*4);
+ uint32 *tex_dest = (uint32*)manager->malloc(tile_size);
+
{
int t = 0;
@@ -340,18 +344,63 @@
}
}
}
+
+ // 1 / 2
+ for (int y = 0; y < tex_height; y += TEXTURE_SPLIT_PIXEL*2) {
+ for (int x = 0; x < tex_width; x += TEXTURE_SPLIT_PIXEL*2) {
+ for (int j = 0; j < TEXTURE_SPLIT_PIXEL*2; j+=2) {
+ for (int i = 0; i < TEXTURE_SPLIT_PIXEL*2; i+=2) {
+ tex_dest[t++] = tex_src[(x+i) + tex_width*(y+j)];
+ }
+ }
+ }
+ }
+
+ // 1 / 4
+ for (int y = 0; y < tex_height; y += TEXTURE_SPLIT_PIXEL*4) {
+ for (int x = 0; x < tex_width; x += TEXTURE_SPLIT_PIXEL*4) {
+ for (int j = 0; j < TEXTURE_SPLIT_PIXEL*4; j+=4) {
+ for (int i = 0; i < TEXTURE_SPLIT_PIXEL*4; i+=4) {
+ tex_dest[t++] = tex_src[(x+i) + tex_width*(y+j)];
+ }
+ }
+ }
+ }
+
+ // 1 / 8
+ for (int y = 0; y < tex_height; y += TEXTURE_SPLIT_PIXEL*8) {
+ for (int x = 0; x < tex_width; x += TEXTURE_SPLIT_PIXEL*8) {
+ for (int j = 0; j < TEXTURE_SPLIT_PIXEL*8; j+=8) {
+ for (int i = 0; i < TEXTURE_SPLIT_PIXEL*8; i+=8) {
+ tex_dest[t++] = tex_src[(x+i) + tex_width*(y+j)];
+ }
+ }
+ }
+ }
+
+ // 1 / 16
+ for (int y = 0; y < tex_height; y += TEXTURE_SPLIT_PIXEL*16) {
+ for (int x = 0; x < tex_width; x += TEXTURE_SPLIT_PIXEL*16) {
+ for (int j = 0; j < TEXTURE_SPLIT_PIXEL*16; j+=16) {
+ for (int i = 0; i < TEXTURE_SPLIT_PIXEL*16; i+=16) {
+ tex_dest[t++] = tex_src[(x+i) + tex_width*(y+j)];
+ }
+ }
+ }
+ }
+
}
- list[id_count-1].t_w = texture_image->w;
- list[id_count-1].t_h = texture_image->h;
+ list[id_count-1].t_w = texture_image->w/2;
+ list[id_count-1].t_h = texture_image->h/2;
list[id_count-1].pixels_orig = (Uint32*)texture_image->pixels;
- list[id_count-1].pixels = tex_dest;
+ list[id_count-1].pixels = tex_dest + image_tmp/4;
texture_id = id_count-1;
- texture_info.t_w = texture_image->w;
- texture_info.t_h = texture_image->h;
+ texture_info.t_w = texture_image->w/2;
+ texture_info.t_h = texture_image->h/2;
texture_info.pixels_orig = (Uint32*)texture_image->pixels;
- texture_info.pixels = tex_dest;
+ texture_info.pixels = tex_dest + image_tmp/4;
printf("[%s] %p\n", filename, tex_dest);
diff -r 5a4f2497c22d -r 17f2138b9d52 TaskManager/Test/test_render/texture.h
--- a/TaskManager/Test/test_render/texture.h Thu Dec 11 11:18:44 2008 +0900
+++ b/TaskManager/Test/test_render/texture.h Thu Dec 11 16:33:39 2008 +0900
@@ -7,29 +7,18 @@
GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
#endif
-#define S_X 128
-#define SSIZE 128*128
-#define SS64 64*64
-#define SS32 32*32
-
-typedef struct {
- Uint32 tx128[SSIZE];
- Uint32 tx64[SS64];
- Uint32 tx32[SS32];
- Uint32 block[SSIZE+SS64+SS32];
-} Sptx;
-
#if 0
-typedef struct Texture{
- int px, py;
- Sptx s[100];
+struct texture_tmp{
+ Uint32 tx128[SSIZE];
+ Uint32 tx64[SS64];
+ Uint32 tx32[SS32];
};
#endif
struct texture_list {
- int t_w, t_h;
- Uint32 *pixels_orig;
- Uint32 *pixels;
+ int t_w, t_h;
+ Uint32 *pixels_orig;
+ Uint32 *pixels;
};
#endif