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:
<script>
var canvas;
var imgElement = document.getElementById('my-image');
var totalLength;
var totalWidth;
var boxHeight = 200;
var boxWidth = 60;
var boxDepth = 80;
var foldHeight = 20;
//var allObject = canvas.getObjects();
initialCanvas(80, 225, boxHeight, foldHeight, boxWidth, boxDepth, 2);
function initialCanvas(initX, initY, boxHeight, insertingFoldHeight, boxWidth, boxDepth, foldCuttingSize)
{
totalLength = 2*boxDepth + 2*boxHeight + insertingFoldHeight +100;
totalWidth = 5*boxWidth;
// $('#myCanvas').attr('width', totalLength);
// $('#myCanvas').attr('height', totalWidth);
canvas = new fabric.Canvas('myCanvas');
new fabric.Image.fromURL('quality.png', function (oImg) {
oImg.set({
width: canvas.width / 4,
height: canvas.height / 4,
originX: 'left',
originY: 'top'
});
oImg.set('angle', 20);
//canvas.add(oImg);
});
new fabric.Image.fromURL('quality.png', function (oImg) {
oImg.set({
width: canvas.width / 4,
height: canvas.height / 4,
originX: 'left',
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);
}
}
}
</script> 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);
}
}
}
</script>
Can someone help me with this? This is my dieline image: