How to use maxrects-packer - 5 common examples

To help you get started, we’ve selected a few maxrects-packer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ct-js / ct-js / src / node_requires / exporter.js View on Github external
tiledImages.push({
                origname: tex.origname,
                tex
            });
        }
    }
    // eager sort
    blocks.sort((a, b) => Math.max(b.height, b.width) > Math.max(a.height, a.width));
    // this is the beginning of a resulting string that will be written to res.js
    let res = 'PIXI.Loader.shared';
    let registry = {};
    const atlases = []; // names of atlases' json files
    const Packer = require('maxrects-packer').MaxRectsPacker;
    const atlasWidth = 2048,
        atlasHeight = 2048;
    const pack = new Packer(atlasWidth, atlasHeight, 0);
    // pack all the frames
    pack.addArray(blocks);
    // get all atlases
    pack.bins.forEach((bin, binInd) => {
        const atlas = document.createElement('canvas');
        atlas.width = bin.width;
        atlas.height = bin.height;
        atlas.x = atlas.getContext('2d');

        const atlasJSON = {
            meta: {
                app: 'https://ctjs.rocks/',
                version: require('electron').remote.app.getVersion(),
                image: `a${binInd}.png`,
                format: 'RGBA8888',
                size: {
github odrick / free-tex-packer / src / client / packers / MaxRectsPacker.js View on Github external
pack(data, method) {
        let options = {
            smart: (method === METHOD.Smart || method === METHOD.SmartSquare),
            pot: false,
            square: (method === METHOD.Square || method === METHOD.SmartSquare)
        };

        let packer = new MaxRectsPackerEngine(this.binWidth, this.binHeight, 0, options);

        let input = [];
        
        for(let item of data) {
            input.push({width: item.frame.w, height: item.frame.h, data: item});
        }

        packer.addArray(input);
        
        let bin = packer.bins[0];
        let rects = bin.rects;
        
        let res = [];
        
        for(let item of rects) {
            item.data.frame.x = item.x;
github odrick / free-tex-packer-core / packers / MaxRectsPacker.js View on Github external
pack(data, method) {
        let options = {
            smart: (method === METHOD.Smart || method === METHOD.SmartArea || method === METHOD.SmartSquare || method === METHOD.SmartSquareArea),
            pot: false,
            square: (method === METHOD.Square || method === METHOD.SquareArea || method === METHOD.SmartSquare || method === METHOD.SmartSquareArea),
            allowRotation: this.allowRotate,
            logic: (method === METHOD.Smart || method === METHOD.Square || method === METHOD.SmartSquare) ? PACKING_LOGIC.MAX_EDGE : PACKING_LOGIC.MAX_AREA
        };

        let packer = new MaxRectsPackerEngine(this.binWidth, this.binHeight, 0, options);

        let input = [];
        
        for(let item of data) {
            input.push({width: item.frame.w, height: item.frame.h, data: item});
        }

        packer.addArray(input);
        
        let bin = packer.bins[0];
        let rects = bin.rects;
        
        let res = [];
        
        for(let item of rects) {
            item.data.frame.x = item.x;
github odrick / free-tex-packer-core / packers / MaxRectsPacker.js View on Github external
let MaxRectsPackerEngine = require("maxrects-packer").MaxRectsPacker;
let PACKING_LOGIC = require("maxrects-packer").PACKING_LOGIC;

let Packer = require("./Packer");

const METHOD = {
    Smart: "Smart",
    SmartArea: "SmartArea",
    Square: "Square",
    SquareArea: "SquareArea",
    SmartSquare: "SmartSquare",
    SmartSquareArea: "SmartSquareArea"
};

class MaxRectsPacker extends Packer {
    constructor(width, height, allowRotate=false) {
        super();
github odrick / free-tex-packer-core / packers / MaxRectsPacker.js View on Github external
pack(data, method) {
        let options = {
            smart: (method === METHOD.Smart || method === METHOD.SmartArea || method === METHOD.SmartSquare || method === METHOD.SmartSquareArea),
            pot: false,
            square: (method === METHOD.Square || method === METHOD.SquareArea || method === METHOD.SmartSquare || method === METHOD.SmartSquareArea),
            allowRotation: this.allowRotate,
            logic: (method === METHOD.Smart || method === METHOD.Square || method === METHOD.SmartSquare) ? PACKING_LOGIC.MAX_EDGE : PACKING_LOGIC.MAX_AREA
        };

        let packer = new MaxRectsPackerEngine(this.binWidth, this.binHeight, 0, options);

        let input = [];
        
        for(let item of data) {
            input.push({width: item.frame.w, height: item.frame.h, data: item});
        }

        packer.addArray(input);
        
        let bin = packer.bins[0];
        let rects = bin.rects;
        
        let res = [];

maxrects-packer

A max rectangle 2d bin packer for packing glyphs or images into multiple sprite-sheet/atlas

MIT
Latest version published 3 years ago

Package Health Score

50 / 100
Full package analysis