Skip to content

Commit

Permalink
generate sequence layer without saving it's material
Browse files Browse the repository at this point in the history
  • Loading branch information
smallpath committed Jun 15, 2017
1 parent 837e802 commit df6d120
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 13 deletions.
65 changes: 59 additions & 6 deletions dist/Sp_memory.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
}
};

var imagePattern = new RegExp('(ai|bmp|bw|cin|cr2|crw|dcr|dng|dib|dpx|eps|erf|exr|gif|hdr|icb|iff|jpe|jpeg|jpg|mos|mrw|nef|orf|pbm|pef|pct|pcx|pdf|pic|pict|png|ps|psd|pxr|raf|raw|rgb|rgbe|rla|rle|rpf|sgi|srf|tdi|tga|tif|tiff|vda|vst|x3f|xyze)', 'i');
$.layer.extend($.layer.prototype, {

getLayerAttr: function getLayerAttr(index) {
Expand Down Expand Up @@ -904,10 +905,20 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
layerInfo.solidColor = mainSource.color;
} else if (mainSource instanceof FileSource && !isNullLayer && !isComp) {
layerInfo.sound = thisLayer.hasAudio;
if (layerInfo.sound) {

if (thisLayer.hasAudio) {
layerInfo.type = 'VideoWithSound';
} else {
layerInfo.type = 'VideoWithoutSound';
var suffix = mainSource.file.toString() || '';
var matched = suffix.split('.').pop();
if (mainSource.isStill === true) {
layerInfo.type = 'VideoWithoutSound';
} else if (matched) {
layerInfo.type = 'VideoWithoutSound';
layerInfo.sequence = 'true';
} else {
layerInfo.type = 'VideoWithoutSound';
}
}
} else if (isComp) {
layerInfo.type = 'Comp';
Expand Down Expand Up @@ -1014,7 +1025,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
return layerInfo;
},

getMaterial: function getMaterial(layerInfo, helperObj, thisLayer) {
getMaterial: function getMaterial(layerInfo, helperObj, thisLayer, isSequence) {
var file = layerInfo.file = thisLayer.source.mainSource.file;
if (this.isSaveMaterial === false) return layerInfo;

Expand All @@ -1029,6 +1040,24 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
var fileContent = thisFile.read();
thisFile.close();
layerInfo.fileBin = encode(fileContent);
if (layerInfo.sequence.toString() === 'true') {
var fileArr = $.layer.testForSequence(thisFile);
if (fileArr.length !== 0) {
var outter = new XML('<fileBinSeq></fileBinSeq>');

$.layer.forEach.call(fileArr, function (sequenceFile, index) {
try {
var tempXmlBigHere = new XML('<imgName>' + encode(sequenceFile.name) + '</imgName>');

var temp = new XML('<imgInfo></imgInfo>');
temp.appendChild(tempXmlBigHere);

outter.appendChild(temp);
} catch (err) {}
});
layerInfo.fileBinSeq = outter;
}
}
} catch (err) {}
} catch (err) {}
}
Expand Down Expand Up @@ -1846,6 +1875,13 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
}
}
if (layer instanceof AVLayer) {
try {
if (xml.sequence.toString() === 'true') {
layer.source.replaceWithSequence(new File(xml.file.toString()), false);
}
} catch (err) {
$.writeln(err.toString());
}
return layer;
} else {
layer = thisComp.layers.addSolid([0, 0, 0], 'fail due to not instanceof AVLayer', 100, 100, 1);
Expand Down Expand Up @@ -2723,6 +2759,25 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
$.layer.errorInfoArr = [];
};

$.layer.testForSequence = function (file) {
var searcher = new RegExp('\\d{4,}');
var files = file.parent.getFiles();
var defaultResult = searcher.exec(file.name);
if (!defaultResult) return [];
var prefix = file.name.replace(defaultResult[0], '');
var finalFiles = [];
for (var i = 0; i < files.length; i++) {
var currentResult = searcher.exec(files[i].name);
if (currentResult) {
var testName = files[i].name.replace(currentResult[0], '');
if (testName === prefix) {
finalFiles.push(files[i]);
}
}
}
return finalFiles;
};

$.layer.writeErrorFile = function () {
var file = new File($.layer.tempFolder.toString() + $.layer.slash.toString() + 'error.txt');
if ($.layer.errorInfoArr.length === 0) {
Expand Down Expand Up @@ -6509,7 +6564,6 @@ module.exports = function () {
}

var xml = sp.getXmlFromLayers(thisComp.selectedLayers, itemName, sp);

sp.saveItemToFile(sp.getFileByName(sp.droplist.selection.text), xml);

var item = sp.gv.add(decodeURIComponent(itemName), sp.getImage(sp.droplist.selection.text, itemName));
Expand Down Expand Up @@ -6846,8 +6900,7 @@ module.exports = function () {
sp.parentDroplist.size.height = sp.droplist.size.height;
sp.parentDroplist.location.y = 0;
sp.parentDroplist.itemSize.width = (parentDroplistWidth - 27 * scale) / scale;
var screen = $.screens[0].toString().split('-').pop().split(':');
sp.droplist.maximumSize = sp.parentDroplist.maximumSize = [undefined, parseInt(screen[1]) - 100];

sp.gv.refresh();
};
this.winClose = function () {
Expand Down
69 changes: 65 additions & 4 deletions lib/AfterEffectsLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
}
}

const imagePattern = new RegExp('(ai|bmp|bw|cin|cr2|crw|dcr|dng|dib|dpx|eps|erf|exr|gif|hdr|icb|iff|jpe|jpeg|jpg|mos|mrw|nef|orf|pbm|pef|pct|pcx|pdf|pic|pict|png|ps|psd|pxr|raf|raw|rgb|rgbe|rla|rle|rpf|sgi|srf|tdi|tga|tif|tiff|vda|vst|x3f|xyze)', 'i')
$.layer.extend($.layer.prototype, {

getLayerAttr: function(index) {
Expand Down Expand Up @@ -78,10 +79,20 @@
layerInfo.solidColor = mainSource.color
} else if (mainSource instanceof FileSource && !isNullLayer && !isComp) {
layerInfo.sound = thisLayer.hasAudio
if (layerInfo.sound) {
// alert(typeof layerInfo.sound)
if (thisLayer.hasAudio) {
layerInfo.type = 'VideoWithSound'
} else {
layerInfo.type = 'VideoWithoutSound'
var suffix = mainSource.file.toString() || ''
var matched = suffix.split('.').pop()
if (mainSource.isStill === true) {
layerInfo.type = 'VideoWithoutSound'
} else if (matched) {
layerInfo.type = 'VideoWithoutSound'
layerInfo.sequence = 'true'
} else {
layerInfo.type = 'VideoWithoutSound'
}
}
} else if (isComp) {
layerInfo.type = 'Comp'
Expand All @@ -93,7 +104,7 @@
layerInfo.type = 'Camera'
break
}

// alert(layerInfo.type)
layerInfo.name = thisLayer.name
layerInfo['@type'] = layerInfo.type

Expand Down Expand Up @@ -188,7 +199,7 @@
return layerInfo
},

getMaterial: function(layerInfo, helperObj, thisLayer) {
getMaterial: function(layerInfo, helperObj, thisLayer, isSequence) {
var file = layerInfo.file = thisLayer.source.mainSource.file
if (this.isSaveMaterial === false) return layerInfo

Expand All @@ -203,6 +214,32 @@
var fileContent = thisFile.read()
thisFile.close()
layerInfo.fileBin = encode(fileContent)
if (layerInfo.sequence.toString() === 'true') {
// alert('上天套餐')
var fileArr = $.layer.testForSequence(thisFile)
if (fileArr.length !== 0) {
var outter = new XML('<fileBinSeq></fileBinSeq>')
// var j = 0
$.layer.forEach.call(fileArr, function(sequenceFile, index) {
// $.writeln('??')
try {
// sequenceFile.open('r')
// sequenceFile.encoding = 'BINARY'
// var content = encode(sequenceFile.read())
// sequenceFile.close()
var tempXmlBigHere = new XML('<imgName>' + encode(sequenceFile.name) + '</imgName>')
// var tempXmlHeres = new XML('<img>' + content + '</img>')
var temp = new XML('<imgInfo></imgInfo>')
temp.appendChild(tempXmlBigHere)
// temp.appendChild(tempXmlHeres)
outter.appendChild(temp)
// j += content.length
// $.writeln(j)
} catch (err) {}
})
layerInfo.fileBinSeq = outter
}
}
} catch (err) { }
} catch (err) { }
}
Expand Down Expand Up @@ -984,6 +1021,11 @@
} catch (err) { $.layer.errorInfoArr.push({ line: $.line, error: err }) }
}
if (layer instanceof AVLayer) {
try {
if (xml.sequence.toString() === 'true') {
layer.source.replaceWithSequence(new File(xml.file.toString()), false)
}
} catch (err) { $.writeln(err.toString()) }
return layer
} else {
layer = thisComp.layers.addSolid([0, 0, 0], 'fail due to not instanceof AVLayer', 100, 100, 1)
Expand Down Expand Up @@ -1812,6 +1854,25 @@
$.layer.errorInfoArr = []
}

$.layer.testForSequence = function(file) {
var searcher = new RegExp('\\d{4,}')
var files = file.parent.getFiles()
var defaultResult = searcher.exec(file.name)
if (!defaultResult) return []
var prefix = file.name.replace(defaultResult[0], '')
var finalFiles = []
for (var i = 0; i < files.length; i++) {
var currentResult = searcher.exec(files[i].name)
if (currentResult) {
var testName = files[i].name.replace(currentResult[0], '')
if (testName === prefix) {
finalFiles.push(files[i])
}
}
}
return finalFiles
}

$.layer.writeErrorFile = function() {
var file = new File($.layer.tempFolder.toString() + $.layer.slash.toString() + 'error.txt')
if ($.layer.errorInfoArr.length === 0) {
Expand Down
7 changes: 4 additions & 3 deletions src/ui/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ module.exports = function() {
}

var xml = sp.getXmlFromLayers(thisComp.selectedLayers, itemName, sp)

sp.saveItemToFile(sp.getFileByName(sp.droplist.selection.text), xml)

var item = sp.gv.add(decodeURIComponent(itemName), sp.getImage(sp.droplist.selection.text, itemName))
Expand Down Expand Up @@ -746,8 +745,10 @@ module.exports = function() {
sp.parentDroplist.size.height = sp.droplist.size.height
sp.parentDroplist.location.y = 0 // fix margin error for mac
sp.parentDroplist.itemSize.width = (parentDroplistWidth - 27 * scale) / scale
var screen = $.screens[0].toString().split('-').pop().split(':')
sp.droplist.maximumSize = sp.parentDroplist.maximumSize = [undefined, parseInt(screen[1]) - 100]
// var screen = $.screens[0].toString().split('-').pop().split(':')
// var max = parseInt(screen[1]) - 500
// if (sp.droplist.size[1] >= max) sp.droplist.size[1] = max
// if (sp.parentDroplist.size[1] >= max) sp.parentDroplist.size[1] = max
sp.gv.refresh()
}
this.winClose = function() {
Expand Down

0 comments on commit df6d120

Please sign in to comment.