예제 #1
0
def encode_vmd_shadowframe(nice: List[vmdstruct.VmdShadowFrame],
                           moreinfo: bool) -> bytearray:
    output = bytearray()
    ###########################################
    # shadow frames
    # first, the number of frames
    if moreinfo:
        core.MY_PRINT_FUNC("...# of shadowframes        = %d" % len(nice))
    output += core.my_pack(fmt_number, len(nice))
    # then, all the actual frames
    for i, frame in enumerate(nice):
        # the shadow value comes in as an int, but it actually stored as a float
        # convert it back to its natural form for packing
        val = (10000 - frame.val) / 100000
        try:
            output += core.my_pack(fmt_shadowframe, [frame.f, frame.mode, val])
        except Exception as e:
            core.MY_PRINT_FUNC(e.__class__.__name__, e)
            core.MY_PRINT_FUNC("line=", i)
            core.MY_PRINT_FUNC("section=shadowframe")
            core.MY_PRINT_FUNC(
                "Err: something went wrong while synthesizing binary output, probably the wrong type/order of values on a line"
            )
            raise RuntimeError()

    return output
예제 #2
0
def encode_vmd_ikdispframe(nice: List[vmdstruct.VmdIkdispFrame],
                           moreinfo: bool) -> bytearray:
    output = bytearray()
    ###########################################
    # disp/ik frames
    # first, the number of frames
    if moreinfo:
        core.MY_PRINT_FUNC("...# of ik/disp frames      = %d" % len(nice))
    output += core.my_pack(fmt_number, len(nice))
    # then, all the actual frames
    for i, frame in enumerate(nice):
        try:
            # pack the first 3 args with the "ikdispframe" template
            output += core.my_pack(
                fmt_ikdispframe,
                [frame.f, frame.disp, len(frame.ikbones)])
            # for each ikbone listed in the template:
            for z in frame.ikbones:
                output += core.my_pack(fmt_ikframe, [z.name, z.enable])
        except Exception as e:
            core.MY_PRINT_FUNC(e.__class__.__name__, e)
            core.MY_PRINT_FUNC("line=", i)
            core.MY_PRINT_FUNC("section=ikdispframe")
            core.MY_PRINT_FUNC(
                "Err: something went wrong while synthesizing binary output, probably the wrong type/order of values on a line"
            )
            raise RuntimeError()

    return output
예제 #3
0
def encode_vmd_lightframe(nice: List[vmdstruct.VmdLightFrame],
                          moreinfo: bool) -> bytearray:
    output = bytearray()
    ###########################################
    # light frames
    # first, the number of frames
    if moreinfo:
        core.MY_PRINT_FUNC("...# of lightframes         = %d" % len(nice))
    output += core.my_pack(fmt_number, len(nice))
    # then, all the actual frames
    for i, frame in enumerate(nice):
        # the RGB come in as ints, but are actually stored as floats... convert them back to floats for packing
        colors = [j / 256 for j in frame.color]
        try:
            output += core.my_pack(fmt_lightframe,
                                   [frame.f, *colors, *frame.pos])
        except Exception as e:
            core.MY_PRINT_FUNC(e.__class__.__name__, e)
            core.MY_PRINT_FUNC("line=", i)
            core.MY_PRINT_FUNC("section=lightframe")
            core.MY_PRINT_FUNC(
                "Err: something went wrong while synthesizing binary output, probably the wrong type/order of values on a line"
            )
            raise RuntimeError()
    return output
예제 #4
0
def encode_vmd_camframe(nice: List[vmdstruct.VmdCamFrame],
                        moreinfo: bool) -> bytearray:
    output = bytearray()
    ###########################################
    # cam frames
    # first, the number of frames
    if moreinfo:
        core.MY_PRINT_FUNC("...# of camframes           = %d" % len(nice))
    output += core.my_pack(fmt_number, len(nice))
    # then, all the actual frames
    for i, frame in enumerate(nice):
        xyz_rads = [math.radians(j) for j in frame.rot]  # degrees to radians
        try:
            packme = [
                frame.f, frame.dist, *frame.pos, *xyz_rads, *frame.interp,
                frame.fov, frame.perspective
            ]
            output += core.my_pack(fmt_camframe, packme)
        except Exception as e:
            core.MY_PRINT_FUNC(e.__class__.__name__, e)
            core.MY_PRINT_FUNC("line=", i)
            core.MY_PRINT_FUNC("section=camframe")
            core.MY_PRINT_FUNC(
                "Err: something went wrong while synthesizing binary output, probably the wrong type/order of values on a line"
            )
            raise RuntimeError()

        # progress thing just because
        core.print_progress_oneline(i / len(nice))
    return output
예제 #5
0
def encode_vmd_morphframe(nice: List[vmdstruct.VmdMorphFrame],
                          moreinfo: bool) -> bytearray:
    output = bytearray()
    ###########################################
    # morph frames
    # first, the number of frames
    if moreinfo:
        core.MY_PRINT_FUNC("...# of morphframes         = %d" % len(nice))
    output += core.my_pack(fmt_number, len(nice))
    # then, all the actual frames
    for i, frame in enumerate(nice):
        try:
            output += core.my_pack(fmt_morphframe,
                                   [frame.name, frame.f, frame.val])
        except Exception as e:
            core.MY_PRINT_FUNC(e.__class__.__name__, e)
            core.MY_PRINT_FUNC("line=", i)
            core.MY_PRINT_FUNC("section=morphframe")
            core.MY_PRINT_FUNC(
                "Err: something went wrong while synthesizing binary output, probably the wrong type/order of values on a line"
            )
            raise RuntimeError()

        # print a progress update every so often just because
        core.print_progress_oneline(ENCODE_PERCENT_BONE +
                                    (ENCODE_PERCENT_MORPH * i / len(nice)))
    return output
예제 #6
0
def encode_vmd_boneframe(nice: List[vmdstruct.VmdBoneFrame],
                         moreinfo: bool) -> bytearray:
    output = bytearray()
    #############################
    # bone frames
    # first, the number of frames
    if moreinfo:
        core.MY_PRINT_FUNC("...# of boneframes          = %d" % len(nice))
    output += core.my_pack(fmt_number, len(nice))
    # then, all the actual frames
    for i, frame in enumerate(nice):
        # assemble the boneframe
        # first, gotta convert from euler to quaternion!
        euler = frame.rot  # x y z
        (w, x, y, z) = core.euler_to_quaternion(euler)  # w x y z
        quat = [x, y, z, w]  # x y z w
        # then, do the part that isn't the interpolation curve (first 9 values in binary, 8 things in frame), save as frame
        try:
            # now encode/pack/append the non-interp, non-phys portion
            packme = [frame.name, frame.f, *frame.pos, *quat]
            # packme.extend(frame.pos)
            # packme.extend(quat)
            output += core.my_pack(fmt_boneframe_no_interpcurve, packme)
            # then, create one line of the interpolation curve (last 16 values of frame obj)
            interp = core.my_pack(fmt_boneframe_interpcurve_oneline,
                                  frame.interp)
        except Exception as e:
            core.MY_PRINT_FUNC(e.__class__.__name__, e)
            core.MY_PRINT_FUNC("line=", i)
            core.MY_PRINT_FUNC("section=boneframe")
            core.MY_PRINT_FUNC(
                "Err: something went wrong while synthesizing binary output, probably the wrong type/order of values on a line"
            )
            raise RuntimeError()
        # do the dumb copy-and-shift thing to rebuild the original 4-line structure of redundant bytes
        interp += interp[1:] + bytes(1) + interp[2:] + bytes(
            2) + interp[3:] + bytes(3)
        # now overwrite the odd missing bytes with physics enable/disable data
        if frame.phys_off is True:
            interp[2] = 99
            interp[3] = 15
        else:
            interp[2] = 0
            interp[3] = 0
        # append the interpolation data onto the real output
        output += interp
        # progress thing just because
        core.print_progress_oneline(ENCODE_PERCENT_BONE * i / len(nice))

    return output
예제 #7
0
def encode_vmd_header(nice: vmdstruct.VmdHeader, moreinfo:bool) -> bytearray:
	output = bytearray()
	if moreinfo: core.MY_PRINT_FUNC("...model name   = JP:'%s'" % nice.modelname)
	##################################
	# header data
	# first, version: if ver==1, then use "Vocaloid Motion Data file", if ver==2, then use "Vocaloid Motion Data 0002"
	if nice.version == 2:
		writeme = ["Vocaloid Motion Data 0002", nice.modelname]
		output += core.my_pack(fmt_header + fmt_modelname_new, writeme)
	elif nice.version == 1:
		writeme = ["Vocaloid Motion Data file", nice.modelname]
		output += core.my_pack(fmt_header + fmt_modelname_old, writeme)
	else:
		core.MY_PRINT_FUNC("ERR: unsupported VMD version value", nice.version)
		raise ValueError
	
	return output