コード例 #1
0
def createMesh(points, tris, texture=None, uvs=None):
    """
    Create a polygon mesh by specifying vertex coordinates and triangle index

	Parameters
	----------
        points: tuple or list
            list or tuple of points
        tris: tuple or list
            list or tuple of triangle indices
        texture: string (optional)
            file path of texture
        uvs: list or tuple (optional)
            list or tuple of  texture uv
	Returns
	-------
        editableFigure
   
    """
    gen = pyxie.shaderGenerator()
    if texture != None:
        gen.setColorTexture(True)
    gen.setBoneCondition(1, 1)

    efig = pyxie.editableFigure("sprite")
    efig.addMaterial("mate", gen)
    efig.addMesh("mesh", "mate")

    efig.setVertexElements("mesh", pyxie.ATTRIBUTE_ID_POSITION, points)
    if uvs:
        efig.setVertexElements("mesh", pyxie.ATTRIBUTE_ID_UV0, uvs)
    efig.setTriangles("mesh", tris)
    efig.addJoint("joint")
    efig.setMaterialParam("mate", "DiffuseColor", (1.0, 1.0, 1.0, 1.0))
    #efig.setMaterialRenderState("mate", "cull_face_enable", False)

    if texture != None:
        efig.setMaterialParamTexture("mate",
                                     "ColorSampler",
                                     texture,
                                     wrap_s=pyxie.SAMPLERSTATE_BORDER,
                                     wrap_t=pyxie.SAMPLERSTATE_BORDER,
                                     minfilter=pyxie.SAMPLERSTATE_NEAREST,
                                     magfilter=pyxie.SAMPLERSTATE_NEAREST)
        efig.setMaterialRenderState("mate", "blend_enable", True)
    return efig
コード例 #2
0
    def _create_device_objects(self):
        self.camera = pyxie.camera('2dcamera')
        self.camera.orthographicProjection = True
        self.camera.position = pyvmath.vec3(0, 0, 1)
        self.camera.screenScale = (1, -1)
        w, h = pyxie.viewSize()
        self.camera.screenOffset = -w, h

        gen = pyxie.shaderGenerator()
        gen.setColorTexture(True)
        gen.setVertexColor(True)
        self.editableFigure = pyxie.editableFigure('font')
        self.editableFigure.addMaterial("mate01", gen)
        self.editableFigure.setMaterialParam("mate01", "DiffuseColor",
                                             (1.0, 1.0, 1.0, 1.0))
        self.editableFigure.setMaterialRenderState("mate01", "blend_enable",
                                                   True)
        self.editableFigure.addJoint('joint')
        self.showcase = pyxie.showcase('imgui')
        self.showcase.add(self.editableFigure)
コード例 #3
0
ファイル: root.py プロジェクト: quangdb-indigames/PyBullets
import os

# import time

# ------------------------------------------------------------
# --pre process

FILENAME = "Lion_Voxel_340.dae"

if os.path.exists("boxinfo.pickle"):
    os.remove("boxinfo.pickle")

if not os.path.exists("boxinfo.pickle"):
    # if True:

    efig = pyxie.editableFigure("efig")
    devtool.loadCollada(FILENAME, efig)

    boxinfo = []
    for i in range(efig.numMeshes):
        aabb = vmath.aabb()
        inverts = efig.getVertexElements(i, pyxie.ATTRIBUTE_ID_POSITION)
        for pos in inverts:
            aabb.insert(pos)
        outverts = []
        for pos in inverts:
            outverts.append(pos - aabb.center)
        efig.setVertexElements(i, pyxie.ATTRIBUTE_ID_POSITION, outverts)
        efig.setJoint(i, position=aabb.center)

        min, max = efig.getMeshAABB(i)
コード例 #4
0
ファイル: __init__.py プロジェクト: indigames/pyxiepython
def convertAssets(src,dst,platform, unit=1.0):
    """
    Convert model and image data to pyxie format
    model(.dae) -> .pyxf
    image(.png .dds .tga .psd ) -> .pyxi

    If model data with the same name as the folder name is found,
    it is regarded as base model data, and other model data in the
    same folder are regarded as motion files, and all are packed
    into one file
    If there is no model data with the same name as the folder name,
    Each model data as base model data and convert separately

    

    :param src: source root folder
    :param dst: destination root folder
    :param platform: target platform (pyxie.TARGET_PLATFORM_XX)
    :param unit: scale unit size of 3d model
    :return: None
    """
    def findImages(path):
        list = []
        for root, dirs, files in os.walk(path):
            if root.find('\.') != -1: continue
            for fname in files:
                name, ext = os.path.splitext(fname)
                if ext == '.png' or ext == '.dds' or ext == '.tga' or ext == '.psd':
                    list.append(os.path.join(root, fname))
        return list
    def createDirectoryTree(filelist, root):
        imageDirectory = dict()
        for img in filelist:
            while True:
                img, file = os.path.split(img)
                if img not in imageDirectory:
                    imageDirectory[img] = {file: 0};
                elif file not in imageDirectory[img]:
                    imageDirectory[img][file] = 0
                if img == root: break
        return imageDirectory
    def findFileFromDiorectoryTree(imageDirectory, file, dir):
        files = imageDirectory.get(dir)
        if files is None: return None
        if file in files:
            return os.path.join(dir, file)
        for d in files:
            _, ext = os.path.splitext(d)
            if ext is '':
                rv = findFileFromDiorectoryTree(imageDirectory, file, os.path.join(dir, d))
                if rv: return rv
        return None
    def findConvertSet(path):
        dict = {}
        for root, dirs, files in os.walk(path):
            if root.find('\.') != -1: continue
            folder = os.path.basename(root)
            baseFile = folder + '.dae'

            folderRule = False
            for f in files:
                if f == baseFile:
                    folderRule = True
                    break

            if folderRule:
                daes = [os.path.join(root, baseFile)]
                for f2 in files:
                    f2_name, f2_ext = os.path.splitext(f2)
                    if f2_ext == '.dae' and f2_name != folder:
                        daes.append(os.path.join(root, f2))
                dict[folder] = daes
            else:
                for f2 in files:
                    f2_name, f2_ext = os.path.splitext(f2)
                    if f2_ext == '.dae':
                        dict[f2_name] = [os.path.join(root, f2)]
        return dict
    def removeRoot(path, root):
        newpath = path.replace(root, '', 1)
        if newpath[0] == '/' or newpath[0] == '\\':
            newpath = newpath[1:]
        return newpath
    def replaceExt(file, ext):
        name, extold = os.path.splitext(file)
        return name + ext
    def readAndCalcHash(srcfile, dstfile, hashfile):
        hashcode = '00000000000000000000000000000000'
        newhash  = 'ffffffffffffffffffffffffffffffff'
        if os.path.exists(dstfile):
            try:
                with open(hashfile, 'r') as f:
                    hashcode = f.read()
            except : None

        fileDataBinary = open(srcfile, 'rb').read()
        if len(fileDataBinary) is not 0:
            hash = hashlib.md5()
            hash.update(fileDataBinary)
            newhash = hash.hexdigest()
        return hashcode,newhash
    def saveHash(hashfile, newhash):
        if newhash != 'ffffffffffffffffffffffffffffffff':
            apputil.makeDirectories(hashfile)
            with open(hashfile, 'w') as f:
                f.write(newhash)

    # convert model and image
    allimages = findImages(src)
    imageDirectory = createDirectoryTree(allimages, src)
    daes = findConvertSet(src)
    allTextures = dict()
    tmpfig = pyxie.editableFigure("tmpfigure")
    for key, data in daes.items():
        tmpfig.clear()
        loadCollada(data[0], tmpfig, unit)
        for i in range(1, len(data)):
            loadColladaAnimation(data[i], tmpfig, unit)
        path, file = os.path.split(data[0])

        texs = tmpfig.getTextureSource()
        for tex in texs:
            filename = os.path.basename(tex['path'])
            current = path
            inputimage = None
            while True:
                inputimage = findFileFromDiorectoryTree(imageDirectory,filename, current)
                if inputimage is not None: break
                if current == src: break
                current,_ = os.path.split(current)
            if inputimage is None:
                print('file not found '+ tex['path'])
            else:
                allTextures[inputimage] = tex;
                inputimage = inputimage.replace('\\', '/')
                inputimage = removeRoot(inputimage,src);
                inputimage,ext = os.path.splitext(inputimage)
                newTex = {'path':inputimage, 'normal': tex['normal'], 'wrap': tex['wrap']}
                tmpfig.replaceTextureSource(tex, newTex)

        outfile = os.path.normpath(data[0].replace(src, dst, 1))
        outfile = replaceExt(outfile, '.pyxf')
        apputil.makeDirectories(outfile)
        tmpfig.mergeMesh()
        tmpfig.saveFigure(outfile)

    for img in allimages:
        if img not in allTextures:
            newTex = {'path': removeRoot(img,src), 'normal': False, 'wrap': False}
            allTextures[img] = newTex

    for key, val in allTextures.items():
        outfile = os.path.normpath(key.replace(src, dst, 1))
        outfile = replaceExt(outfile, '.pyxi')
        hashfile = os.path.normpath(key.replace(src, '.tmp/hash', 1))
        hashcode, newhash = readAndCalcHash(key, outfile, hashfile)
        if hashcode != newhash:
            apputil.makeDirectories(outfile)
            convertTextureToPlatform(key, outfile, platform, val['normal'], val['wrap'])
            saveHash(hashfile, newhash)
        else:
            print("skip convert {} because no change".format(key))
コード例 #5
0
    def VoxelModelProcess(self):
        # ------------------------------------------------------------
        # --pre process

        FILENAME = "TestVoxel/Lion_Voxel_340_04.dae"
        BOXINFOR_PATH = "TestVoxel/boxinfo.pickle"
        CONSTRUCT_BOXDATA_PATH = "TestVoxel/newConstructBoxData.pickle"

        # if os.path.exists("TestVoxel/boxinfo.pickle"):
        # 	os.remove("TestVoxel/boxinfo.pickle")

        if not os.path.exists(BOXINFOR_PATH) or not os.path.exists(
                CONSTRUCT_BOXDATA_PATH):
            print("Come here")
            # if True:

            efig = pyxie.editableFigure("efig")
            devtool.loadCollada(FILENAME, efig)

            boxinfo = []
            for i in range(efig.numMeshes):
                aabb = vmath.aabb()
                inverts = efig.getVertexElements(i,
                                                 pyxie.ATTRIBUTE_ID_POSITION)
                for pos in inverts:
                    aabb.insert(pos)
                outverts = []
                for pos in inverts:
                    outverts.append(pos - aabb.center)
                efig.setVertexElements(i, pyxie.ATTRIBUTE_ID_POSITION,
                                       outverts)
                efig.setJoint(i, position=aabb.center)

                min, max = efig.getMeshAABB(i)
                pos, rot, _ = efig.getJoint(i)
                data = (
                    (pos.x, pos.y, pos.z),
                    (rot.x, rot.y, rot.z, rot.w),
                    (min.x, min.y, min.z),
                    (max.x, max.z, max.z),
                )
                boxinfo.append(data)
            newBoxData = self.HandleBoxData(boxinfo)

            newConstructBoxData = dict()
            newConstructBoxData.update({
                "size": self.size,
                "center": self.center,
                "newBoxData": newBoxData
            })

            src = efig.getTextureSource()
            for tex in src:
                texfilename = os.path.basename(tex['path'])
                name, _ = os.path.splitext(texfilename)
                newtex = tex.copy()
                newtex['path'] = "TestVoxel/" + name
                print("New text path: ", newtex['path'])
                efig.replaceTextureSource(tex, newtex)
                filepath = glob.glob('**/' + texfilename, recursive=True)
                print("File path: ", filepath)
                if len(filepath) is not 0:
                    devtool.convertTextureToPlatform(
                        filepath[0], os.path.join(".", "TestVoxel\\" + name),
                        pyxie.TARGET_PLATFORM_PC, tex['normal'], tex['wrap'])
                    print("Path joining: ", os.path.join(".", name))

            with open(BOXINFOR_PATH, "wb") as f:
                pickle.dump(boxinfo, f)
            with open(CONSTRUCT_BOXDATA_PATH, "wb") as f:
                pickle.dump(newConstructBoxData, f)

            efig.mergeMesh()
            efig.saveFigure("TestVoxel/Lion_Enemy")