Ejemplo n.º 1
0
    def id_to_render(self, bid):
        if bid == "bone":
            cherrypy.response.headers['Content-Type'] = 'application/octet-stream'
            return open('bone.js')

        infile = "data/%s.obj" % bid
        outfile = "output/%s.js" % bid

        if not os.path.isfile(outfile): convert_obj_three.convert_ascii(infile, "", "", outfile)
        cherrypy.response.headers['Content-Type'] = 'text/javascript'
        return open(outfile, 'r').read()
Ejemplo n.º 2
0
def GetJSON(filebase="_stuff/visit", TYPE="ascii"):
    # Save the window as OBJ file format.
    swa = GetSaveWindowAttributes()
    swa.fileName = filebase
    swa.family = 0
    swa.format = swa.OBJ
    SetSaveWindowAttributes(swa)
    name = SaveWindow()

    # If there was a .visit file, get the contents of it.
    filenames = []
    s = os.stat(name)
    if s.st_size == 0:
        visitfile = name[:-4] + ".visit"
        try:
            s = os.stat(visitfile)
            filenames = [ x[:-1] for x in open(visitfile, "rt").readlines()[1:]]
        except OSError:
            pass
    else:
        filenames = [name]

    # Convert each of the files to JSON.
    jsons = []
    for f in filenames:
        outfile = f[:-4] + ".js"
        if TYPE == "ascii":
            morphfiles = ""
            colorfiles = ""
            convert_ascii(f, morphfiles, colorfiles, outfile)
        else:
            convert_binary(f, outfile)
        # Read the json back in
        cydumb = json.loads(open(outfile).read())
        jsons.append(cydumb)
    return jsons
        basehuman = getHuman()
        humanargparser.addRig(basehuman, rig_file)
        prxy = mhproxy.loadProxy(basehuman, proxy_file)
        mesh, obj = prxy.loadMeshAndObject(basehuman)

        print("prxy = ", prxy)
        # export
        infile = Path(prxy.obj_file)
        outfile = outdir.joinpath(group.lower()).joinpath(prxy.name,prxy.name + '.json')
        outfile.dirname().makedirs_p()
        if outfile.isfile(): continue
        
        convert_ascii(
            infile=infile,
            morphfiles='',
            colorfiles='',
            outfile=outfile,
            licence=json.dumps(LicenseInfo().asDict()),
            mtllib=material_to_mtl(prxy.material, texdir=os.path.dirname(outfile))
        )
        print(outfile)
        
        # some extra data to add to the file
        skeleton = basehuman.getSkeleton()
        bones = parse_skeleton_bones(skeleton)
        skeletonMetadata  = {
            "name": skeleton.name,
            "version": skeleton.version,
            "description": skeleton.description,
            "plane_map_strategy": skeleton.plane_map_strategy,
            "license": skeleton.license.asDict(),
        }
from os import listdir
from os.path import join
from convert_obj_three import convert_ascii
import sys

path = "C:/Users/Aleksander/Documents/3dsMaxProjects/Threejs_platformer/export/"

def is_object_file(input_file):
	if input_file[-4:] == ".obj":
		return True
	else:
		return False

files = [ f for f in listdir(path) if is_object_file(join(path,f)) ]

fileStart = ""

if len(sys.argv) > 1:
	fileStart = sys.argv[1]

for f in files:

	if (fileStart != "") & f.startswith(fileStart):
		input = path + f
		output = f[:-3] + "js"
		convert_ascii(input, "", "", output)
	elif fileStart == "":
		input = path + f
		output = f[:-3] + "js"
		convert_ascii(input, "", "", output)