Friday, August 5, 2016

javascript - Dieline image to a box in Three.js


I have created a dieline image using Three.js. Now I need to convert this dieline into a box.


This is my code for the dieline:


           originY: 'top'
});
//oImg.set('angle', 20);
//canvas.add(oImg);
});


var dieLineIntials = {
boxLength: boxHeight,
insertingFoldHeight: insertingFoldHeight,
boxWidth: boxWidth,
boxDepth: boxDepth,
foldCuttingSize : foldCuttingSize,
initX: initX,
initY: initY
};


//var pointsInInch = 72;
var pointsInInch = 72;

var dieLineIntialsForPDF = {
boxHeight: boxHeight * pointsInInch,
insertingFoldHeight: insertingFoldHeight * pointsInInch,
boxWidth: boxWidth * pointsInInch,
boxDepth: boxDepth * pointsInInch,
foldCuttingSize : foldCuttingSize* pointsInInch,

initX: 150,
initY: boxWidth * pointsInInch + 250
};

var startX = startY = pointX = pointY = width = height = 0;
drawShipperBox(1,canvas, dieLineIntials);

//ADDING CURVE*************************************************
/*var y = 100;
var x= 50

var param = 'M '+x+','+y+' Q '+2*x+','+x/2+' '+3*x+','+y;
var line = new fabric.Path(param, { fill: '', stroke: 'black'});
line.selectable = false;
canvas.add(line);*/
//ADDING CURVE*************************************************
}

function getPDFFile () {
html2canvas($("#myCanvas"), {
onrendered: function(canvas) {

var imgData = canvas.toDataURL(
'image/png');
var doc = new jsPDF({
orientation: 'landscape',
unit: 'mm',
format: [totalWidth, totalLength]
});
doc.addImage(imgData, 'PNG', 10, 10);
doc.save('sample-file.pdf');
}

});
}

var textures = {};
var textfields = {};
function getObjectProperties(canvas) {
var objects = canvas.getObjects();
for (var i in objects) {
if( objects[i].get('type') == 'image'){
textures[i] = {

src : objects[i].getSrc(),
angle : objects[i].get('angle'),
height : objects[i].get('height'),
width : objects[i].get('width'),
left : objects[i].get('left'),
top: objects[i].get('top'),
coOrds : objects[i].getCoords()
}
}else if(objects[i].get('type') == 'textbox'){
textFields[i] = {

text : objects[i].get('text'),
angle : objects[i].get('angle'),
height : objects[i].get('height'),
width : objects[i].get('width'),
left : objects[i].get('left'),
top: objects[i].get('top'),
coOrds : objects[i].getCoords()
}
}
}

console.log(textures);
console.log(textfields);
}

function setObjectProperties(canvas) {
var textureIndexes = Object.keys(textures);
var textfiledIndexes = Object.keys(textfields);
console.log(textureIndexes);
console.log(textfiledIndexes);
var objects = canvas.getObjects();

for (var i in objects) {
console.log(i);
if(textureIndexes.indexOf(i) != -1){
console.log('UPADTE');
objects[i].set('angle', textures[i].angle);
objects[i].set('height', textures[i].height);
objects[i].set('width', textures[i].width);
objects[i].set('left', textures[i].left);
objects[i].set('top', textures[i].top);
objects[i].set('coOrds', textures[i].coOrds);

}
}

}



Can someone help me with this? This is my dieline image:





No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...