Exemple #1
0
def ObjToCollision(Object,
                   bank=2,
                   offset=0,
                   nowaterboxes=0,
                   scale=1,
                   ReverseFaces=False):
    global trisOffset, vertsOffset, waterOffset
    maxs = [-9000, -9000, -9000]
    mins = [9000, 9000, 9000]
    #I know this code is ugly. gtfo
    wotf.resetvars()
    bank = bank << 24
    f = open(Object, "r")
    wotf.reverse_faces = ReverseFaces
    wotf.fdir = path.split(Object)[0]
    if wotf.fdir: wotf.fdir += wotf.slash
    object_data = wotf.fix_obj(f.read())
    wotf.parse_obj(object_data)
    f.close()
    i = 0
    vert_count, tri_count = 0, 0
    collision_types, collision_tris, verts, water = "", "", "", ""
    for entry in wotf.mtls:
        collision_types += "\x00\x00\x00\x00\x00\x00\x00\x00"
        for triangle in entry[7]:
            collision_tris += pack(">HHHHQ", i, triangle[0][0], triangle[0][1],
                                   triangle[0][2], 0)
            tri_count += 1
        i += 1
    range3 = range(3)
    for vert in wotf.verts:
        verts += pack(">hhh", int(vert[0] * scale), int(vert[1] * scale),
                      int(vert[2] * scale))
        for i in range3:
            if int(vert[i] * scale) > maxs[i]:
                maxs[i] = int(vert[i] * scale) + 1
            elif int(vert[i] * scale) < mins[i]:
                mins[i] = int(vert[i] * scale) - 1
        vert_count += 1
    verts = align(verts, 8)
    for i in range(0, nowaterboxes * 400, 400):
        water += pack(">hhhhhxxxxBB", 0 + i, 0, 0 + i, 400 + i, 400 + i, 1, 0)
    typesOffset = offset | bank
    trisOffset = typesOffset + len(collision_types) | bank
    vertsOffset = trisOffset + len(collision_tris) | bank
    waterOffset = vertsOffset + len(verts) | bank
    headerOffset = waterOffset + len(water) | bank
    camDataOffset = 0
    data = collision_types + collision_tris + verts + water
    del collision_types, collision_tris, verts, water
    data += pack(">hhhhhhHxxLHxxLLLHxxL", mins[0], mins[1], mins[2], maxs[0],
                 maxs[1], maxs[2], vert_count, vertsOffset, tri_count,
                 trisOffset, typesOffset, camDataOffset, nowaterboxes,
                 waterOffset if nowaterboxes else 0)
    return data, headerOffset
Exemple #2
0
def BuildMap(MeshObject,
             MeshScale=1,
             NoActors=0,
             NoObjects=0,
             StartTime=ZELDATIME,
             TimeSpeed=NOTIME,
             SkyBoxDisabled=False,
             ReverseFaces=False):

    header = ">QQLBBxxLhbxLLBBxxLBBxxLQ"
    meshHeader = ">xBxxLLLxxxxBxxxxxxxxxxx"
    bank = 3

    ObjectList, ActorList = "", ""
    for i in range(NoObjects & 0xF):
        ObjectList += pack(">H", SafeObjects[i])
    ObjectList = align(ObjectList, 8)
    for i in range(NoActors & 0x7F):
        ActorList += pack(">HhhhHHHH", 8, 0, 0, i * 30, 0, 0, 0, i & 7)
    #Calculate offsets
    ObjectOffset = calcsize(header) + (bank << 24)
    ActorOffset = ObjectOffset + len(ObjectList)
    MeshHeaderOffset = ActorOffset + len(ActorList)
    MeshOffset = MeshHeaderOffset + calcsize(meshHeader)

    #Convert Mesh
    wotf.resetvars()
    f = open(MeshObject, "r")
    wotf.reverse_faces = ReverseFaces
    wotf.fdir = path.split(MeshObject)[0]
    if wotf.fdir: wotf.fdir += wotf.slash
    object_data = wotf.fix_obj(f.read())
    f.close()
    wotf.parse_obj(object_data)
    del object_data
    wotf.vtx_scale = [MeshScale, MeshScale, MeshScale]
    MeshData, DisplayListOffset, TexInfo = wotf.ParsedMeshToOoT(
        wotf.mtls, wotf.verts, wotf.texcoords, wotf.normals, bank, MeshOffset,
        bank, MeshOffset)
    del TexInfo

    data = pack(header, 0x1600000000000000, 0x0801000000000000, 0x12000000,
                int(SkyBoxDisabled), int(SkyBoxDisabled), 0x10000000,
                StartTime, TimeSpeed, 0x0A000000, MeshHeaderOffset, 0x0B,
                NoObjects, ObjectOffset, 0x01, NoActors, ActorOffset,
                0x1400000000000000)
    data += ObjectList
    del ObjectList
    data += ActorList
    del ActorList
    data += pack(meshHeader, 1, MeshHeaderOffset + 0xC,
                 MeshHeaderOffset + 0x14, DisplayListOffset, 1)
    data += MeshData
    del MeshData
    return align(data, 16)
Exemple #3
0
def BuildMap(MeshObject, MeshScale=1,NoActors=0, NoObjects=0, StartTime=ZELDATIME, TimeSpeed=NOTIME,SkyBoxDisabled=False,ReverseFaces=False):

    header=">QQLBBxxLhbxLLBBxxLBBxxLQ"
    meshHeader=">xBxxLLLxxxxBxxxxxxxxxxx"
    bank=3
    
    ObjectList, ActorList="", ""
    for i in range(NoObjects&0xF):
        ObjectList+=pack(">H",SafeObjects[i])
    ObjectList=align(ObjectList,8)
    for i in range(NoActors&0x7F):
        ActorList+=pack(">HhhhHHHH", 8, 0, 0, i*30, 0, 0, 0, i&7)
    #Calculate offsets
    ObjectOffset=calcsize(header)+(bank<<24)
    ActorOffset=ObjectOffset+len(ObjectList)
    MeshHeaderOffset=ActorOffset+len(ActorList)
    MeshOffset=MeshHeaderOffset+calcsize(meshHeader)
    
    #Convert Mesh
    wotf.resetvars()
    f=open(MeshObject,"r")
    wotf.reverse_faces=ReverseFaces
    wotf.fdir=path.split(MeshObject)[0]
    if wotf.fdir: wotf.fdir+=wotf.slash
    object_data = wotf.fix_obj(f.read())
    f.close()
    wotf.parse_obj(object_data)
    del object_data
    wotf.vtx_scale = [MeshScale,MeshScale,MeshScale]
    MeshData, DisplayListOffset, TexInfo = wotf.ParsedMeshToOoT(wotf.mtls,wotf.verts,wotf.texcoords,wotf.normals, bank, MeshOffset, bank, MeshOffset)
    del TexInfo
    
    data=pack(header,
	0x1600000000000000,
	0x0801000000000000,
	0x12000000, int(SkyBoxDisabled), int(SkyBoxDisabled),
	0x10000000, StartTime, TimeSpeed,
	0x0A000000, MeshHeaderOffset,
	0x0B, NoObjects, ObjectOffset,
	0x01, NoActors, ActorOffset,
	0x1400000000000000)
    data+=ObjectList
    del ObjectList
    data+=ActorList
    del ActorList
    data+=pack(meshHeader, 1, MeshHeaderOffset+0xC, MeshHeaderOffset+0x14, DisplayListOffset, 1)
    data+=MeshData
    del MeshData
    return align(data,16)
Exemple #4
0
def ObjToCollision(Object, bank=2, offset=0, nowaterboxes=0, scale=1,ReverseFaces=False):
    global trisOffset,vertsOffset, waterOffset
    maxs = [-9000, -9000, -9000]
    mins = [9000, 9000, 9000]
    #I know this code is ugly. gtfo
    wotf.resetvars()
    bank=bank<<24
    f=open(Object,"r")
    wotf.reverse_faces=ReverseFaces
    wotf.fdir=path.split(Object)[0]
    if wotf.fdir: wotf.fdir+=wotf.slash
    object_data = wotf.fix_obj(f.read())
    wotf.parse_obj(object_data)
    f.close()
    i=0
    vert_count,tri_count=0,0
    collision_types,collision_tris,verts,water="","","",""
    for entry in wotf.mtls:
        collision_types+="\x00\x00\x00\x00\x00\x00\x00\x00"
        for triangle in entry[7]:
            collision_tris+=pack(">HHHHQ",i,triangle[0][0],triangle[0][1],triangle[0][2],0)
            tri_count+=1
        i+=1
    range3=range(3)
    for vert in wotf.verts:
        verts+=pack(">hhh",int(vert[0]*scale),int(vert[1]*scale),int(vert[2]*scale))
        for i in range3:
            if int(vert[i]*scale) > maxs[i]:
                maxs[i]=int(vert[i]*scale)+1
            elif int(vert[i]*scale) < mins[i]:
                mins[i]=int(vert[i]*scale)-1
        vert_count+=1
    verts=align(verts,8)
    for i in range(0,nowaterboxes*400,400):
        water+=pack(">hhhhhxxxxBB",0+i,0,0+i,400+i,400+i,1,0)
    typesOffset	= offset	|bank
    trisOffset	= typesOffset+len(collision_types)	|bank
    vertsOffset	= trisOffset+len(collision_tris)	|bank
    waterOffset	= vertsOffset+len(verts)	|bank
    headerOffset	= waterOffset+len(water)	|bank
    camDataOffset	= 0
    data=collision_types+collision_tris+verts+water
    del collision_types,collision_tris,verts,water
    data+=pack(">hhhhhhHxxLHxxLLLHxxL",mins[0],mins[1],mins[2],maxs[0],maxs[1],maxs[2],
    	vert_count, vertsOffset, tri_count, trisOffset, typesOffset, camDataOffset,nowaterboxes, waterOffset if nowaterboxes else 0)
    return data, headerOffset