Commit e837057d authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

copying selected models

parent b480ea74
......@@ -15,6 +15,10 @@ $(function(){
});
$('.copy').on('click',function(e){
copy_models();
});
});
function parse_list(res){
......@@ -29,10 +33,12 @@ function parse_list(res){
$(this).find("model").each(function(){
var mname = $(this).attr("name");
var basepath = 'models/_all/'+name;
var item = [
'<li>',
' <a href=\'viewer.html?basepath=models/_all/'+name+'&path='+mname+'\'>'+mname+'</a>',
' <input type=\'checkbox\' class=\'chkbox\' set=\''+name+'\' model=\''+mname+'\'/>',
' <a href=\'viewer.html?basepath='+basepath+'&path='+mname+'\'>'+mname+'</a>',
'</li>'
].join('\n');
......@@ -42,4 +48,21 @@ function parse_list(res){
});
}
function copy_models(){
$(".chkbox").each(function(){
if ($(this).prop("checked")){
$.ajax({
url: "select.php?cmd=copy&set="+$(this).attr('set')+"&model="+$(this).attr('model'),
success: function(response){
console.log(response);
}
});
}
});
}
\ No newline at end of file
......@@ -21,7 +21,13 @@
</head>
<body>
<div>
<button class='copy'>Copy checked to <i>models/</i></button>
</div>
<div id="content">
</div>
<div>
<button class='copy'>Copy checked to <i>models/</i></button>
</div>
</body>
</html>
<?php
$base = "models/_all";
$base0 = "models";
$base = "$base0/_all";
$showall = false;
......@@ -8,6 +9,47 @@ if (isset($_GET['showall'])){
$showall = true;
}
if ($_GET['cmd']=='copy'){
$set = $_GET['set'];
$model = $_GET['model'];
$path_from = "$base/$set/$model/*";
$path_to = "$base0/$model/v0";
if (!is_dir($path_to)){
$old = umask(0);
$res = mkdir($path_to,0777,true);
umask($old);
if (!$res){
die("FAIL: $set/$model: check 'w' rights on models/");
}
}
exec("cp -r $path_from $path_to");
//generate default kml
$ts = str_replace("_",".",$model);
$kml = "$base0/$model/$model.kml";
if (!is_file($kml)){
file_put_contents($kml,generate_default_kml($model,$ts));
}
//gen thumbnail
$thumb_src = "$base0/$model/v0/$model-00-D0.0.jpeg";
$thumb_res = "$base0/$model/thumb.jpeg";
if (!is_file($thumb_res)){
if (is_file($thumb_src)){
create_thumbnail($thumb_src,$thumb_res);
}
}
die("DONE: $set/$model was copied to models/");
}
$series = selective_scandir($base,false);
$res = "";
......@@ -67,4 +109,81 @@ function return_xml($str){
}
function generate_default_kml($name,$ts){
$kml = <<<TXT
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<PhotoOverlay>
<name>$name</name>
<visibility>1</visibility>
<shape>rectangle</shape>
<TimeStamp>
<when>$ts</when>
</TimeStamp>
<Camera>
<longitude>-111.9328843</longitude>
<latitude>40.7233861</latitude>
<altitude>1305.1</altitude>
<heading>65</heading>
<tilt>90</tilt>
<roll>00</roll>
</Camera>
<Icon>
<href>x3d/$name.x3d</href>
</Icon>
<ExtendedData>
<OriginalData>
<longitude>-111.9328843</longitude>
<latitude>40.7233861</latitude>
<altitude>1305.1</altitude>
<heading>65</heading>
<tilt>90</tilt>
<roll>0</roll>
</OriginalData>
</ExtendedData>
</PhotoOverlay>
</Document>
</kml>
TXT;
return $kml;
}
function create_thumbnail($path,$thumbname){
$file = $path;
if (extension_loaded('imagick')){
$imagick = new Imagick($file);
$imagick->trimImage(0);
$w = $imagick->getImageWidth();
$h = $imagick->getImageHeight();
//$imagick->borderImage('black', 100, 100);
// $imagick->cropImage($w/2, $h/4, $w/4, $h/4);
//$imagick->thumbnailImage(200, 100, true, true);
$imagick->cropThumbnailImage(198, 98);
$imagick->borderImage('gray', 1, 1);
$imagick->writeImage($thumbname);
}else{
echo "Extension imagick is no loaded.\n";
}
return 0;
}
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment