def readLayr2(layr_bytes, layers): ''' Read the object's layer data. ''' layer = Layer() layer.index, flags = struct.unpack(">HH", layr_bytes[0:4]) # FreeCAD.Console.PrintMessage("Reading Object Layer %d:\n" %(layer.index)) offset = 4 pivot, offset = getFloats(layr_bytes, offset, 3) layer.pivot = (pivot[0], pivot[1], pivot[2]) layr_name, name_len = readString(layr_bytes[offset:]) offset += name_len if name_len > 2 and layr_name != 'noname': layer.name = layr_name else: layer.name = "Layer %d" % layer.index if len(layr_bytes) == offset+2: parentIdx, offset = getShort(layr_bytes, offset) parent = layers.get(parentIdx) parent.subds.append(layer) layers[layer.index] = layer return layer
def getArrayPoint3f(values): v = [] if len(values) >= 4: count, offset = getInt(values, 0) while (count > 0): floats, offset = getFloats(values, offset, 3) v.append(floats) count -= 1 return v
def calcCoordinatesI(data): l, o = getInt(data, 0) cnt = len(data) / 12 p = numpy.zeros((cnt, 3), numpy.float32) i = 0 while (o < len(data)): f, o = getFloats(data, o, 3) p[i:0:3] = f i += 1 return p
def calcCoordinates(data): l, o = getInt(data, 0) cnt = len(data) // 16 p = numpy.zeros((cnt, 3), numpy.float32) i = 0 while (o < len(data)): w, o = getInt(data, o) f, o = getFloats(data, o, 3) p[i, ] = f i += 1 return p
def readSurf2(surf_bytes, objMaterials): ''' Read the object's surface data. ''' surf = Material() name, name_len = readString(surf_bytes) if len(name) != 0: surf.name = name # We have to read this, but we won't use it...yet. s_name, s_name_len = readString(surf_bytes[name_len:]) offset = name_len + s_name_len chunk_len = len(surf_bytes) while offset < chunk_len: subchunk_name, = UNPACK_NAME(surf_bytes[offset:offset + 4]) offset += 4 subchunk_len, offset = getShort(surf_bytes, offset) # Now test which subchunk it is. if subchunk_name == b'COLR': c, dummy = getFloats(surf_bytes, offset, 3) surf.colr = tuple(c) elif subchunk_name == b'DIFF': surf.diff, dummy = getFloat(surf_bytes, offset) elif subchunk_name == b'LUMI': surf.lumi, dummy = getFloat(surf_bytes, offset) elif subchunk_name == b'SPEC': surf.spec, dummy = getFloat(surf_bytes, offset) elif subchunk_name == b'REFL': surf.refl, dummy = getFloat(surf_bytes, offset) elif subchunk_name == b'TRAN': surf.tran, dummy = getFloat(surf_bytes, offset) elif subchunk_name == b'RIND': surf.rind, dummy = getFloat(surf_bytes, offset) elif subchunk_name == b'GLOS': surf.glos, dummy = getFloat(surf_bytes, offset) elif subchunk_name == b'RBLR': surf.rblr, dummy = getFloat(surf_bytes, offset) elif subchunk_name == b'TBLR': surf.tblr, dummy = getFloat(surf_bytes, offset) elif subchunk_name == b'TRNL': surf.trnl, dummy = getFloat(surf_bytes, offset) elif subchunk_name == b'SHRP': surf.shrp, dummy = getFloat(surf_bytes, offset) elif subchunk_name == b'SMAN': s_angle, offset = getFloat(surf_bytes, offset) if s_angle > 0.0: surf.smooth = True offset += subchunk_len objMaterials[surf.name] = surf
def readPoints(pnt_bytes, layer): ''' Read the layer's points. ''' # FreeCAD.Console.PrintMessage(" Reading Layer Points\n") offset = 0 chunk_len = len(pnt_bytes) while offset < chunk_len: pnts, offset = getFloats(pnt_bytes, offset, 3) # Re-order the points so that the mesh has the right pitch, # the pivot already has the correct order. pnts = [pnts[0] - layer.pivot[0],\ pnts[2] - layer.pivot[1],\ pnts[1] - layer.pivot[2]] layer.pnts.append(pnts)
def getColorMax(colors, idx): prp = getProperty(colors, idx) if (prp is not None): c, o = getFloats(prp.data, 15, 3) return (c[0], c[1], c[2]) return None