Example #1
0
 def __init__(self):
     self.data = EggData()
     self.vtxPool = EggVertexPool('mopath')
     self.data.addChild(self.vtxPool)
     self.eggGroup = EggGroup('group')
     self.data.addChild(self.eggGroup)
     self.myverts = []
Example #2
0
def make_fov(sweep=90, steps=16, scale=100):
    z = 1 + random.uniform(-0.01, 0.01)

    data = EggData()

    vp = EggVertexPool('fan')
    data.addChild(vp)

    poly = EggPolygon()
    data.addChild(poly)

    v = EggVertex()
    v.setPos(Point3D(0, 0, z))
    poly.addVertex(vp.addVertex(v))

    rads = deg2Rad(sweep)

    for i in range(steps + 1):
        a = rads * i / steps
        y = math.sin(a)
        x = math.cos(a)

        v = EggVertex()
        v.setPos(Point3D(x*scale, y*scale, z))
        poly.addVertex(vp.addVertex(v))

    node = loadEggData(data)
    np = NodePath(node)
    np.setH(sweep/2)
    return np
Example #3
0
    def __init__(self, in_file, out_file):
        #New container for data:
        self.data = EggData()

        #New Container for vertex:
        self.vertexPool = EggVertexPool('model')

        #Adding vertexPool to the main data container:
        self.data.addChild(self.vertexPool) 
        self.load(in_file)
        self.data.setCoordinateSystem(CSZupRight)
        self.data.writeEgg(out_file)
Example #4
0
class epic():
    def __init__(self):
        self.egg = EggData()
        self.loadFile()
        list = self.getUVList(self.egg)
        self.setupGraph(list)

    def setupGraph(self, pointsList):  #pointsList is LPoint2d
        for point in pointsList:
            #plt.plot(np.array([point[0], point[1]]))
            plt.scatter(point[0], point[1])
        plt.grid(True)
        plt.savefig("test.png")
        plt.title(self.egg.egg_filename)
        plt.show()

    def getUVList(self, eggFile):
        uvList = []
        # Some models don't get pass through the vertexPool check
        # so the UVs for smaller models don't get picked up
        for vertexPool in eggFile.getChildren():
            if not isinstance(vertexPool, EggVertexPool):
                continue
            for vertex in vertexPool:
                if not vertex.hasUv():
                    continue
                uvList.append(vertex.getUv())  #matplotlib lol
        return uvList

    def browseModel(self):
        path = Path(
            askopenfilename(filetypes=(("Panda3D Model Files", "*.egg"),
                                       ("EGG", "*.egg"))))
        return path

    def loadFile(self):
        filename = self.browseModel()
        if str(filename) == ".":
            return
        try:
            self.egg.read(filename)
        except:
            print(str(filename) + " could not be loaded!")
Example #5
0
    def createGizmo(self, angleDegrees=360, numSteps=16, axis=0, scale=10):
        data = EggData()

        vp = EggVertexPool('fan')
        data.addChild(vp)

        poly = EggPolygon()
        data.addChild(poly)

        v = EggVertex()
        v.setPos(Point3D(0, 0, 0))
        poly.addVertex(vp.addVertex(v))

        angleRadians = deg2Rad(angleDegrees)

        for i in range(numSteps + 1):
            a = angleRadians * i / numSteps
            y = math.sin(a) * scale
            x = math.cos(a) * scale
            v = EggVertex()
            if axis is 0:
                v.setPos(Point3D(x, 0, y))
            elif axis is 1:
                v.setPos(Point3D(x, y, 0))
            else:
                v.setPos(Point3D(0, x, y))
            poly.addVertex(vp.addVertex(v))
        node = loadEggData(data)
        return NodePath(node)
Example #6
0
 def toEgg(self):
     # make a new egg
     egg = EggData()
     # convert polygon faces
     if len(self.faces) > 0:
         for objname in self.objects:
             for groupname in self.groups:
                 self.__facestoegg(egg, objname, groupname)
     # convert polylines
     if len(self.polylines) > 0:
         for objname in self.objects:
             for groupname in self.groups:
                 self.__polylinestoegg(egg, objname, groupname)
     return egg
Example #7
0
class createNurbsCurve():
    def __init__(self):
        self.data = EggData()
        self.vtxPool = EggVertexPool('mopath')
        self.data.addChild(self.vtxPool)
        self.eggGroup = EggGroup('group')
        self.data.addChild(self.eggGroup)
        self.myverts = []

    def addPoint(self, pos):
        eggVtx = EggVertex()
        eggVtx.setPos(Point3D(pos[0], pos[1], pos[2]))
        self.myverts.append(eggVtx)
        self.vtxPool.addVertex(eggVtx)

    def getNodepath(self):
        myCurve = EggNurbsCurve()
        myCurve.setup(3, len(self.myverts) + 3)
        myCurve.setCurveType(1)
        for i in self.myverts:
            myCurve.addVertex(i)
        self.eggGroup.addChild(myCurve)
        return NodePath(loadEggData(self.data))
Example #8
0
 def toEgg(self, verbose=True):
     if verbose: print("converting...")
     # make a new egg
     egg = EggData()
     # convert polygon faces
     if len(self.faces) > 0:
         for objname in self.objects:
             for groupname in self.groups:
                 self.__facestoegg(egg, objname, groupname)
     # convert polylines
     if len(self.polylines) > 0:
         for objname in self.objects:
             for groupname in self.groups:
                 self.__polylinestoegg(egg, objname, groupname)
     return egg
Example #9
0
def makeEgg(filename):

    # Egg data
    vp = EggVertexPool('sky')

    data = EggData()
    data.addChild(vp)
    data.setCoordinateSystem(1)  # CS_zup_right

    # Vertices
    vmap = {}
    for idx, (x, y, z) in enumerate(vertices):
        vmap[idx] = makeVertex(vp, x, y, z)

    # Faces
    for (i1, i2, i3) in indices:
        v1 = vmap[i1]
        v2 = vmap[i2]
        v3 = vmap[i3]
        makePoly(data, [v1, v2, v3])

    # Save
    data.recomputePolygonNormals()
    data.writeEgg(Filename(filename))
Example #10
0
    def make_root_node(self):
        egg_root = EggData()
        egg_root.set_coordinate_system(CS_zup_right)  # Z-up

        egg_comment = EggComment(
            '', 'KITSUNETSUKI Asset Tools by kitsune.ONE - '
            'https://github.com/kitsune-ONE-team/KITSUNETSUKI-Asset-Tools')
        egg_root.add_child(egg_comment)

        return egg_root
def fbx2egg(fbx_path, egg_path):
    manager, scene = FbxCommon.InitializeSdkObjects()
    FbxCommon.LoadScene(manager, scene, fbx_path)

    prepare_scene(scene)

    data = EggData()
    data.addChild(EggCoordinateSystem(CSYupRight)) # TODO: read coordinate system from fbx

    group = EggGroup("walking") # TODO: get name from fbx anim layer
    group.setDartType(EggGroup.DTDefault)

    traverse_joints(scene, scene.GetRootNode(), group)

    data.addChild(group)
    data.writeEgg(egg_path)
Example #12
0
def makeEgg(filename):

  # Egg data
  vp = EggVertexPool('sky')

  data = EggData()
  data.addChild(vp)
  data.setCoordinateSystem(1) # CS_zup_right

  # Vertices
  vmap = {}
  for idx, (x, y, z) in enumerate(vertices):
    vmap[idx] = makeVertex(vp, x, y, z)

  # Faces
  for (i1, i2, i3) in indices:
    v1 = vmap[i1]
    v2 = vmap[i2]
    v3 = vmap[i3]
    makePoly(data, [v1, v2, v3])

  # Save
  data.recomputePolygonNormals()
  data.writeEgg(Filename(filename))
def fbx2egg_animation(fbx_path, egg_path):
    manager, scene = FbxCommon.InitializeSdkObjects()
    FbxCommon.LoadScene(manager, scene, fbx_path)

    prepare_scene(scene)

    data = EggData()
    data.addChild(EggCoordinateSystem(CSYupRight))

    skeleton = EggTable("<skeleton>")

    walking = EggTable("walking") # TODO: get name from animation layer
    walking.setTableType(EggTable.stringTableType("bundle"))
    walking.addChild(skeleton)

    table = EggTable()
    table.addChild(walking)

    for layer in get_anim_layers(scene):
        traverse_animation_curves(scene, scene.GetRootNode(), layer, skeleton)

    data.addChild(table)
    data.writeEgg(egg_path)
Example #14
0
    def make_circle(self, num_steps):
        data = EggData()

        vertex_pool = EggVertexPool('fan')
        data.addChild(vertex_pool)

        poly = EggPolygon()
        data.addChild(poly)

        for i in range(num_steps + 1):
            angle = 2 * math.pi * i / num_steps
            y = math.sin(angle) * config.minimap.size / 2
            x = math.cos(angle) * config.minimap.size / 2

            vertex = EggVertex()
            vertex.setPos(Point3D(x, 0, y))
            poly.addVertex(vertex_pool.addVertex(vertex))

        node = loadEggData(data)
        return node
Example #15
0
    def createCuttingPlanes(self):
        self.planes = self.render.attachNewNode("planes")
        pl = self.planes.attachNewNode("pl")
        data = EggData()
        self.planedata = []

        vp = EggVertexPool('plane')
        data.addChild(vp)

        fac = 1.0
        expanse = 10.0
        rng = 4
        for i in range(-rng, rng):
            poly = EggPolygon()
            data.addChild(poly)

            self.planedata.append(i * fac)

            v = EggVertex()
            v.setPos(Point3D(i * fac, -expanse, -expanse))
            poly.addVertex(vp.addVertex(v))
            v = EggVertex()
            v.setPos(Point3D(i * fac, -expanse, +expanse))
            poly.addVertex(vp.addVertex(v))
            v = EggVertex()
            v.setPos(Point3D(i * fac, +expanse, +expanse))
            poly.addVertex(vp.addVertex(v))
            v = EggVertex()
            v.setPos(Point3D(i * fac, +expanse, -expanse))
            poly.addVertex(vp.addVertex(v))

        node = loadEggData(data)
        np = NodePath(node)
        np.reparentTo(pl)
        np.setColor(0, 1, 0, 1)
        np.setTwoSided(True)
        np.setTransparency(TransparencyAttrib.MAlpha)
        np.setAlphaScale(0.1)
        np.setCollideMask(BitMask32(0x0))
        return self.planes
Example #16
0
def GenerateCollisionEgg(heightmap, output, input='data/collision3k.egg', scale=100.0):
    input_egg = EggData()
    input_egg.read(input)
    output_egg = EggData()
    output_egg.setCoordinateSystem(CS_default)
    output_egg.stealChildren(input_egg)
    VertexPool = output_egg.getChildren()[1]
    print("Generating mesh, this may take a while...", end="")
    for i in range(VertexPool.getHighestIndex()):
        if i%20000 == 0:
            try:
                base.graphicsEngine.renderFrame()
                print('.', end="")
            except:
                pass
        vert = VertexPool.getVertex(i)
        x0, y0, _ = vert.getPos3()
        #x, y = int(floor(x0+0.5)), int(floor(y0+0.5))
        x, y = int(x0), int(y0)
        if x==512: x=511
        elif x==0: x=1
        if y==512: y=511
        elif y==0: y=1
        vert.setPos(LPoint3d(x0, y0, heightmap.getBright(x,512-y)*scale))

    output_egg.writeEgg(output)
Example #17
0
class STL2EGG():
    def __init__(self, in_file, out_file):
        #New container for data:
        self.data = EggData()

        #New Container for vertex:
        self.vertexPool = EggVertexPool('model')

        #Adding vertexPool to the main data container:
        self.data.addChild(self.vertexPool) 
        self.load(in_file)
        self.data.setCoordinateSystem(CSZupRight)
        self.data.writeEgg(out_file)

    def load(self, filename):
        f = open(filename, 'r')
        header = f.read(6)
        isASCII = ( header== 'solid ')
        if isASCII:
            self.name = f.readline()
            self.parseASCII(f)
        else:
            f.close
            f = open(filename, 'rb')
            self.parseBin(f)
                
    def getName(self):
        return self.name
           
    def readVecteur(self, data):
        v = EggVertex()
        x,y,z = struct.unpack('fff', data)        
        v.setPos(Point3D(x,y,z))
        return v 
                  
    def parseBin(self, f):
        print "Parsing Bin File"
        Header = f.read(80)
        Nb_Face = struct.unpack('i', f.read(4))[0]

        print "Nombre de face : %i" % (Nb_Face)
        for i in range(0,Nb_Face):
            self.poly = EggPolygon()
            self.data.addChild(self.poly)

            # Normal struct
            normal = self.readVecteur(f.read(12))
            u      = self.readVecteur(f.read(12))
            v      = self.readVecteur(f.read(12))
            w      = self.readVecteur(f.read(12))
            attrib   = struct.unpack('H'  , f.read(2))[0]   # Attributes

            #Adding Vertex to Triangle 
            self.poly.addVertex(self.vertexPool.addVertex(u))
            self.poly.addVertex(self.vertexPool.addVertex(v))
            self.poly.addVertex(self.vertexPool.addVertex(w))
            self.poly.recomputePolygonNormal()
            self.poly.setColor( VBase4( 0.0, 0.0, 0.5, 0.5) )

    def parseASCII(self,f ):       
        for line in f:
            line = line.lower().strip()
            commande = line.split(" ")
            Nb_Param = len(commande)
            try:
                {'facet'    : self.facet,
                 'outer'    : self.outer,
                 'vertex'   : self.vertex,
                 'endloop'  : self.endloop,
                 'endfacet' : self.endfacet}[commande[0]](commande,Nb_Param)
            except KeyError:
                pass

    def facet(self,commande,Nb_Param):
        if (Nb_Param==5 and commande[1] == "normal"):
            #We are Ignoring normal --> will be computed later
            #Creating a new polygon :
            self.poly = EggPolygon()
            self.data.addChild(self.poly)

    def outer(self,commande,Nb_Param):
        pass

    def vertex(self,commande,Nb_Param):
        if (Nb_Param==4):
            x,y,z = float(commande[1]),float(commande[2]),float(commande[3])
            if (self.poly != None):
                #Creating a new vertex with coords :
                v = EggVertex()
                v.setPos(Point3D(x,y,z))

                #Adding the new Vertex to the polygon :
                self.poly.addVertex(self.vertexPool.addVertex(v))

    def endloop(self,commande,Nb_Param):
        #End of the Loop : 
        self.poly.recomputePolygonNormal()

        #As STL files don't contain colors:
        self.poly.setColor( VBase4( 0.0, 0.0, 0.5, 0.5) )

    def endfacet(self,commande,Nb_Param):
        pass
Example #18
0
 def __init__(self):
     self.egg = EggData()
     self.loadFile()
     list = self.getUVList(self.egg)
     self.setupGraph(list)
Example #19
0
            print("Warning: %s does not exist!" % filepath)
            shutil.copyfile(errorImage, filecheck)
            continue

        shutil.copyfile(filepath, filecheck)


# if outputFile:
#    if path.exists('texList.txt'):
#        os.remove('texList.txt')

with open('texList.txt', 'w+') as fp:
    pass

for model in eggFiles:
    egg = EggData()
    egg.read(model)
    texList = getTextureList(egg)
    cloneTextureDirs(texList, model)
    if verboseList:
        print(model, texList)
    if outputFile:
        with open('texList.txt', 'a') as f:
            print("%s\n%s\n" % (model, texList), file=f)

# Post migration
dirList = []
for dirs in os.listdir(os.path.join(eggDir, eggOutputDir)):
    dirList.append(os.path.join(eggDir, eggOutputDir, dirs))

#print(os.path.join(eggDir, eggOutputDir))
Example #20
0
def DisplacementUVSphere(radius,
                         heightmap,
                         scale,
                         rings=5,
                         sectors=5,
                         inv_texture_u=False,
                         inv_texture_v=True):
    data = EggData()
    pool = EggVertexPool('pool')
    vertices = []
    data.addChild(pool)
    R = 1. / (rings)
    S = 1. / (sectors)
    for r in range(0, rings + 1):
        for s in range(0, sectors + 1):
            cos_s = cos(2 * pi * s * S + pi)
            sin_s = sin(2 * pi * s * S + pi)
            sin_r = sin(pi * r * R)
            cos_r = cos(pi * r * R)
            x = cos_s * sin_r
            y = sin_s * sin_r
            z = cos_r
            vertex = EggVertex()
            u = s * S
            v = r * R
            height = radius + heightmap.get_height_uv(u, v) * scale
            vertex.setPos(LPoint3d(x * height, y * height, z * height))
            if inv_texture_v:
                v = 1.0 - v
            if inv_texture_u:
                u = 1.0 - u
            vertex.setUv(LPoint2d(u, v))
            pool.addVertex(vertex)
            vertices.append(vertex)

    index = 0
    for r in range(0, rings):
        for s in range(0, sectors):
            poly = EggPolygon()
            data.addChild(poly)
            poly.addVertex(vertices[index + sectors + 1])
            poly.addVertex(vertices[index])
            poly.addVertex(vertices[index + sectors])

            poly = EggPolygon()
            data.addChild(poly)
            poly.addVertex(vertices[index + sectors + 1])
            poly.addVertex(vertices[index + 1])
            poly.addVertex(vertices[index])
            index += 1
    data.removeUnusedVertices(True)
    data.recomputeVertexNormals(45)
    data.recomputeTangentBinormal(GlobPattern(""))
    node = loadEggData(data)
    path = NodePath(node)
    path.flattenStrong()
    return path
Example #21
0
def write(filename: str, egg_data: egg.EggData) -> None:
    """write egg data to a file"""

    egg_data.writeEgg(core.Filename(filename))