Beispiel #1
0
    def __init__(self, filename, compile=True, buffer=None):
        VisibleNode.__init__(self)
        Translator.__init__(self)

        self.rotX = 0.0
        self.rotY = 0.0
        self.rotZ = 0.0

        self.scale = 1.0

        if Model.dlcache.has_key(filename):
            self._displayList = Model.dlcache[filename]
            bb = Model.bbcache[filename]
        else:
            if buffer is None:
                self._dom = dom3ds.read_3ds_file(filename)
            else:
                self._dom = dom3ds.read_3ds_mem(buffer)
            self._model = glmodel.GLModel(self._dom, self._loadTexture)
            bb = self._model.bounding_box()
            Model.bbcache[filename] = bb
            if compile:
                self._displayList = self._model.create_dl()
                Model.dlcache[filename] = self._displayList
            else:
                self._displayList = None
        self._center = (bb[0] + bb[1]) / 2
        self._modelScale = 1.0 / max(abs(bb[0] - bb[1]))
Beispiel #2
0
 def ReadFile(self):
     dom = dom3ds.read_3ds_file(self._filename,tight=False)
     for j,d_nobj in enumerate(dom.mdata.objects):
         if type(d_nobj.obj) != dom3ds.N_TRI_OBJECT:
             continue
         for d_point in d_nobj.obj.points.array:
             print d_point
             pass
         d_texverts = [ tuple(tpt) for tpt in d_nobj.obj.texverts.array ]
         for d_face in d_nobj.obj.faces.array:
             pass
         for k,d_material in enumerate(d_nobj.obj.faces.materials):
             pass
Beispiel #3
0
def read(filename):
    dom = dom3ds.read_3ds_file(filename,tight=False)

    for j,d_nobj in enumerate(dom.mdata.objects):
        if type(d_nobj.obj) != dom3ds.N_TRI_OBJECT:
            continue
        verts = []
        if d_nobj.obj.points:
            for d_point in d_nobj.obj.points.array:
                verts.append([d_point[0],d_point[1],d_point[2]])
            meshdata = []
            for d_face in d_nobj.obj.faces.array:
                meshdata.append([verts[int(d_face[i])] for i in xrange(3)])
            m = [tuple(r) for r in d_nobj.obj.matrix.array]
            m = m[0] + m[1] + m[2] + m[3]
            placement = FreeCAD.Placement(FreeCAD.Matrix(*m))
            mesh = Mesh.Mesh(meshdata)
            obj = FreeCAD.ActiveDocument.addObject("Mesh::Feature","Mesh")
            obj.Mesh = mesh
            obj.Placement = placement
        else:
            print "Skipping object without vertices array: ",d_nobj.obj
Beispiel #4
0
def read(filename):
    dom = dom3ds.read_3ds_file(filename, tight=False)

    for j, d_nobj in enumerate(dom.mdata.objects):
        if type(d_nobj.obj) != dom3ds.N_TRI_OBJECT:
            continue
        verts = []
        if d_nobj.obj.points:
            for d_point in d_nobj.obj.points.array:
                verts.append([d_point[0], d_point[1], d_point[2]])
            meshdata = []
            for d_face in d_nobj.obj.faces.array:
                meshdata.append([verts[int(d_face[i])] for i in xrange(3)])
            m = [tuple(r) for r in d_nobj.obj.matrix.array]
            m = m[0] + m[1] + m[2] + m[3]
            placement = FreeCAD.Placement(FreeCAD.Matrix(*m))
            mesh = Mesh.Mesh(meshdata)
            obj = FreeCAD.ActiveDocument.addObject("Mesh::Feature", "Mesh")
            obj.Mesh = mesh
            obj.Placement = placement
        else:
            print "Skipping object without vertices array: ", d_nobj.obj
Beispiel #5
0
def import3ds(filename):
    """Import a 3DS file into the current scene of Blender.

    Usage:

        import3ds(filename)

    Implementation notes:

    1. Must be run from within Blender, of course.

    2. It does not handle smoothing data at all: output is all solid.

    3. If a texture cannot be found, it does a case-insensitive search
       of the directory; useful on case-sensitive systems when reading
       a 3DS file made on a case-insensitive systems by some ignorant
       fellow.

    4. If a texture is not in PNG or JPEG format, it saves a copy of
       the texture as a PNG file in the same directory.  Blender uses
       the copy for the texture, since Blender only understands JPEG
       and PNG.  Useful for when said ignorant fellow uses a BMP file.

    """

    dom = dom3ds.read_3ds_file(filename,tight=False)

    material_dict = {}
    texture_dict = {}

    b_scene = Blender.Scene.getCurrent()

    for j,d_material in enumerate(dom.mdata.materials):
        b_mat = Blender.Material.New("Material%d" % j)
        b_mat.rgbCol = getcolor(d_material.diffuse.color)
        b_mat.specCol = (0.0,0.0,0.0)
        material_dict[d_material.name.value] = b_mat
        if d_material.texmap is not None:
            b_image = Blender.Image.Load(
                getimage(d_material.texmap.filename.value))
            texture_dict[d_material.name.value] = b_image

    for j,d_nobj in enumerate(dom.mdata.objects):
        if type(d_nobj.obj) != dom3ds.N_TRI_OBJECT:
            continue
        b_obj = Blender.Object.New("Mesh","Object%d" % j)
        b_mesh = Blender.NMesh.New("Mesh%d" % j)
        for d_point in d_nobj.obj.points.array:
            b_vert = Blender.NMesh.Vert(d_point[0],d_point[1],d_point[2])
            b_mesh.verts.append(b_vert)
        d_texverts = [ tuple(tpt) for tpt in d_nobj.obj.texverts.array ]
        for d_face in d_nobj.obj.faces.array:
            vpt = [ b_mesh.verts[int(d_face[i])] for i in range(3) ]
            tpt = [ d_texverts[int(d_face[i])] for i in range(3) ]
            b_face = Blender.NMesh.Face(vpt)
            b_face.uv = tpt
            b_mesh.faces.append(b_face)
        for k,d_material in enumerate(d_nobj.obj.faces.materials):
            b_mesh.materials.append(material_dict[d_material.name])
            for i in d_material.array:
                b_mesh.faces[int(i)].mat = k
                b_image = texture_dict.get(d_material.name)
                if b_image is not None:
                    b_mesh.faces[int(i)].image = b_image
        b_matrix = Blender.Mathutils.Matrix(
            *[tuple(r) for r in d_nobj.obj.matrix.array])
        b_obj.setMatrix(b_matrix)
        b_obj.link(b_mesh)
        b_scene.link(b_obj)