Initial upload
This commit is contained in:
commit
b5514d29f4
117
LICENSE
Normal file
117
LICENSE
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
CC0 1.0 Universal
|
||||||
|
|
||||||
|
Statement of Purpose
|
||||||
|
|
||||||
|
The laws of most jurisdictions throughout the world automatically confer
|
||||||
|
exclusive Copyright and Related Rights (defined below) upon the creator and
|
||||||
|
subsequent owner(s) (each and all, an "owner") of an original work of
|
||||||
|
authorship and/or a database (each, a "Work").
|
||||||
|
|
||||||
|
Certain owners wish to permanently relinquish those rights to a Work for the
|
||||||
|
purpose of contributing to a commons of creative, cultural and scientific
|
||||||
|
works ("Commons") that the public can reliably and without fear of later
|
||||||
|
claims of infringement build upon, modify, incorporate in other works, reuse
|
||||||
|
and redistribute as freely as possible in any form whatsoever and for any
|
||||||
|
purposes, including without limitation commercial purposes. These owners may
|
||||||
|
contribute to the Commons to promote the ideal of a free culture and the
|
||||||
|
further production of creative, cultural and scientific works, or to gain
|
||||||
|
reputation or greater distribution for their Work in part through the use and
|
||||||
|
efforts of others.
|
||||||
|
|
||||||
|
For these and/or other purposes and motivations, and without any expectation
|
||||||
|
of additional consideration or compensation, the person associating CC0 with a
|
||||||
|
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
|
||||||
|
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
|
||||||
|
and publicly distribute the Work under its terms, with knowledge of his or her
|
||||||
|
Copyright and Related Rights in the Work and the meaning and intended legal
|
||||||
|
effect of CC0 on those rights.
|
||||||
|
|
||||||
|
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||||
|
protected by copyright and related or neighboring rights ("Copyright and
|
||||||
|
Related Rights"). Copyright and Related Rights include, but are not limited
|
||||||
|
to, the following:
|
||||||
|
|
||||||
|
i. the right to reproduce, adapt, distribute, perform, display, communicate,
|
||||||
|
and translate a Work;
|
||||||
|
|
||||||
|
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||||
|
|
||||||
|
iii. publicity and privacy rights pertaining to a person's image or likeness
|
||||||
|
depicted in a Work;
|
||||||
|
|
||||||
|
iv. rights protecting against unfair competition in regards to a Work,
|
||||||
|
subject to the limitations in paragraph 4(a), below;
|
||||||
|
|
||||||
|
v. rights protecting the extraction, dissemination, use and reuse of data in
|
||||||
|
a Work;
|
||||||
|
|
||||||
|
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||||
|
European Parliament and of the Council of 11 March 1996 on the legal
|
||||||
|
protection of databases, and under any national implementation thereof,
|
||||||
|
including any amended or successor version of such directive); and
|
||||||
|
|
||||||
|
vii. other similar, equivalent or corresponding rights throughout the world
|
||||||
|
based on applicable law or treaty, and any national implementations thereof.
|
||||||
|
|
||||||
|
2. Waiver. To the greatest extent permitted by, but not in contravention of,
|
||||||
|
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
|
||||||
|
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
|
||||||
|
and Related Rights and associated claims and causes of action, whether now
|
||||||
|
known or unknown (including existing as well as future claims and causes of
|
||||||
|
action), in the Work (i) in all territories worldwide, (ii) for the maximum
|
||||||
|
duration provided by applicable law or treaty (including future time
|
||||||
|
extensions), (iii) in any current or future medium and for any number of
|
||||||
|
copies, and (iv) for any purpose whatsoever, including without limitation
|
||||||
|
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
|
||||||
|
the Waiver for the benefit of each member of the public at large and to the
|
||||||
|
detriment of Affirmer's heirs and successors, fully intending that such Waiver
|
||||||
|
shall not be subject to revocation, rescission, cancellation, termination, or
|
||||||
|
any other legal or equitable action to disrupt the quiet enjoyment of the Work
|
||||||
|
by the public as contemplated by Affirmer's express Statement of Purpose.
|
||||||
|
|
||||||
|
3. Public License Fallback. Should any part of the Waiver for any reason be
|
||||||
|
judged legally invalid or ineffective under applicable law, then the Waiver
|
||||||
|
shall be preserved to the maximum extent permitted taking into account
|
||||||
|
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
|
||||||
|
is so judged Affirmer hereby grants to each affected person a royalty-free,
|
||||||
|
non transferable, non sublicensable, non exclusive, irrevocable and
|
||||||
|
unconditional license to exercise Affirmer's Copyright and Related Rights in
|
||||||
|
the Work (i) in all territories worldwide, (ii) for the maximum duration
|
||||||
|
provided by applicable law or treaty (including future time extensions), (iii)
|
||||||
|
in any current or future medium and for any number of copies, and (iv) for any
|
||||||
|
purpose whatsoever, including without limitation commercial, advertising or
|
||||||
|
promotional purposes (the "License"). The License shall be deemed effective as
|
||||||
|
of the date CC0 was applied by Affirmer to the Work. Should any part of the
|
||||||
|
License for any reason be judged legally invalid or ineffective under
|
||||||
|
applicable law, such partial invalidity or ineffectiveness shall not
|
||||||
|
invalidate the remainder of the License, and in such case Affirmer hereby
|
||||||
|
affirms that he or she will not (i) exercise any of his or her remaining
|
||||||
|
Copyright and Related Rights in the Work or (ii) assert any associated claims
|
||||||
|
and causes of action with respect to the Work, in either case contrary to
|
||||||
|
Affirmer's express Statement of Purpose.
|
||||||
|
|
||||||
|
4. Limitations and Disclaimers.
|
||||||
|
|
||||||
|
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||||
|
surrendered, licensed or otherwise affected by this document.
|
||||||
|
|
||||||
|
b. Affirmer offers the Work as-is and makes no representations or warranties
|
||||||
|
of any kind concerning the Work, express, implied, statutory or otherwise,
|
||||||
|
including without limitation warranties of title, merchantability, fitness
|
||||||
|
for a particular purpose, non infringement, or the absence of latent or
|
||||||
|
other defects, accuracy, or the present or absence of errors, whether or not
|
||||||
|
discoverable, all to the greatest extent permissible under applicable law.
|
||||||
|
|
||||||
|
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||||
|
that may apply to the Work or any use thereof, including without limitation
|
||||||
|
any person's Copyright and Related Rights in the Work. Further, Affirmer
|
||||||
|
disclaims responsibility for obtaining any necessary consents, permissions
|
||||||
|
or other rights required for any use of the Work.
|
||||||
|
|
||||||
|
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||||
|
party to this document and has no duty or obligation with respect to this
|
||||||
|
CC0 or use of the Work.
|
||||||
|
|
||||||
|
For more information, please see
|
||||||
|
<http://creativecommons.org/publicdomain/zero/1.0/>
|
||||||
|
|
45
README.md
Normal file
45
README.md
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# Minetest to POVRAY exporter v0.1
|
||||||
|
|
||||||
|
# ToC:
|
||||||
|
|
||||||
|
-- INTRODUCTION
|
||||||
|
|
||||||
|
-- REQUIREMENTS
|
||||||
|
|
||||||
|
-- USAGE
|
||||||
|
|
||||||
|
-- KNOWN ERRORS, LIMITATIONS AND TO-DOs
|
||||||
|
|
||||||
|
===============================
|
||||||
|
|
||||||
|
# INTRODUCTION
|
||||||
|
|
||||||
|
"Minetest to POVRAY exporter" (named MtPe for short) is (going to be) a set of scripts to export maps (or parts of) to POVRAY-compatible
|
||||||
|
scenery file. Then one is allowed to make renders and animations of the scenery.
|
||||||
|
You might ask "Why did you use PHP?" I say "Why not!" It has got several functions that make your life easier (such as string-indexed arrays).
|
||||||
|
|
||||||
|
===============================
|
||||||
|
|
||||||
|
# REQUIREMENTS
|
||||||
|
|
||||||
|
MtPe requires python2, php5, mysql and povray >3.5.
|
||||||
|
It is designed to run on linux.
|
||||||
|
During development it was tested with povray 3.6 and 3.7, both working well.
|
||||||
|
MySQL currently stores world's data exported from sqlite dataset, but sqlite3 functions in php will work as well.
|
||||||
|
|
||||||
|
===============================
|
||||||
|
|
||||||
|
# USAGE
|
||||||
|
|
||||||
|
[TODO]
|
||||||
|
|
||||||
|
===============================
|
||||||
|
|
||||||
|
# KNOWN ERRORS, LIMITATIONS AND TO-DOs
|
||||||
|
|
||||||
|
- POVRAY uses a lot of memory and CPU - it is recommended NOT to run MtPe on the same server that holds the world itself.
|
||||||
|
- Due to RAM limitations you need to carefully set range to be exported. Exporting too many chunks will crash POVRAY or hang your machine. Export script will work correctly, as it reads one chunk at a time. Caution: it produces HUGE text files!
|
||||||
|
- It is recommended to have pre-existing set of textures and models for POVRAY to work with. The "export_dictionary.php" script will go through any chunk in the world and make POVRAY-compatible files (blocks.inc and blocks_textures.inc) to be modified by the user - one of which holds the blocks and objects, the other holds textures.
|
||||||
|
- MySQL is currently being used to store world's data. I'd like to stick with it for now, as I am going to recompile Minetest to use it as a backend. Beware NOT TO USE InnoDB engine there! Use MyISAM as it will run faster.
|
||||||
|
- As "export_dictionary.php" has no database to save it's results it will go through EVERY chunk every time you run it. Scanning of 990000 chunks took about 5 hours on a dual core pentium 4 machine with 3GB RAM. Currently it reads 100 chunks at a time from the dataset to the queue. Tuning this value can improve performance.
|
||||||
|
- "unzlib.py" and "unpack_coords.py" scripts are just workarounds for me being stupid and unable to write working procedures for unpacking chunk's coordinates and unpacking chunk's data.
|
146
dump_for_mysql.py
Executable file
146
dump_for_mysql.py
Executable file
@ -0,0 +1,146 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import re
|
||||||
|
import fileinput
|
||||||
|
|
||||||
|
def this_line_is_useless(line):
|
||||||
|
useless_es = [
|
||||||
|
'BEGIN TRANSACTION',
|
||||||
|
'COMMIT',
|
||||||
|
'sqlite_sequence',
|
||||||
|
'CREATE UNIQUE INDEX',
|
||||||
|
'PRAGMA foreign_keys=OFF',
|
||||||
|
]
|
||||||
|
for useless in useless_es:
|
||||||
|
if re.search(useless, line):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def has_primary_key(line):
|
||||||
|
return bool(re.search(r'PRIMARY KEY', line))
|
||||||
|
|
||||||
|
searching_for_end = False
|
||||||
|
for line in fileinput.input():
|
||||||
|
if this_line_is_useless(line):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# this line was necessary because ''); was getting
|
||||||
|
# converted (inappropriately) to \');
|
||||||
|
if re.match(r".*, ''\);", line):
|
||||||
|
line = re.sub(r"''\);", r'``);', line)
|
||||||
|
|
||||||
|
if re.match(r'^CREATE TABLE.*', line):
|
||||||
|
searching_for_end = True
|
||||||
|
|
||||||
|
m = re.search('CREATE TABLE "?([a-zA-Z_]*)"?(.*)', line)
|
||||||
|
if m:
|
||||||
|
name, sub = m.groups()
|
||||||
|
line = "DROP TABLE IF EXISTS %(name)s;\nCREATE TABLE IF NOT EXISTS `%(name)s`%(sub)s\n"
|
||||||
|
line = line % dict(name=name, sub=sub)
|
||||||
|
else:
|
||||||
|
m = re.search('INSERT INTO "([a-zA-Z_]*)"(.*)', line)
|
||||||
|
if m:
|
||||||
|
line = 'INSERT INTO %s%s\n' % m.groups()
|
||||||
|
line = line.replace('"', r'\"')
|
||||||
|
line = line.replace('"', "'")
|
||||||
|
line = re.sub(r"([^'])'t'(.)", "\1THIS_IS_TRUE\2", line)
|
||||||
|
line = line.replace('THIS_IS_TRUE', '1')
|
||||||
|
line = re.sub(r"([^'])'f'(.)", "\1THIS_IS_FALSE\2", line)
|
||||||
|
line = line.replace('THIS_IS_FALSE', '0')
|
||||||
|
|
||||||
|
# Add auto_increment if it's not there since sqlite auto_increments ALL
|
||||||
|
# primary keys
|
||||||
|
if searching_for_end:
|
||||||
|
if re.search(r"integer(?:\s+\w+)*\s*PRIMARY KEY(?:\s+\w+)*\s*,", line):
|
||||||
|
line = line.replace("PRIMARY KEY", "PRIMARY KEY AUTO_INCREMENT")
|
||||||
|
# replace " and ' with ` because mysql doesn't like quotes in CREATE commands
|
||||||
|
if line.find('DEFAULT') == -1:
|
||||||
|
line = line.replace(r'"', r'`').replace(r"'", r'`')
|
||||||
|
else:
|
||||||
|
parts = line.split('DEFAULT')
|
||||||
|
parts[0] = parts[0].replace(r'"', r'`').replace(r"'", r'`')
|
||||||
|
line = 'DEFAULT'.join(parts)
|
||||||
|
|
||||||
|
# And now we convert it back (see above)
|
||||||
|
if re.match(r".*, ``\);", line):
|
||||||
|
line = re.sub(r'``\);', r"'');", line)
|
||||||
|
|
||||||
|
if searching_for_end and re.match(r'.*\);', line):
|
||||||
|
searching_for_end = False
|
||||||
|
|
||||||
|
if re.match(r"CREATE INDEX", line):
|
||||||
|
line = re.sub('"', '`', line)
|
||||||
|
|
||||||
|
print line,
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import re
|
||||||
|
import fileinput
|
||||||
|
|
||||||
|
def this_line_is_useless(line):
|
||||||
|
useless_es = [
|
||||||
|
'BEGIN TRANSACTION',
|
||||||
|
'COMMIT',
|
||||||
|
'sqlite_sequence',
|
||||||
|
'CREATE UNIQUE INDEX',
|
||||||
|
'PRAGMA foreign_keys=OFF',
|
||||||
|
]
|
||||||
|
for useless in useless_es:
|
||||||
|
if re.search(useless, line):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def has_primary_key(line):
|
||||||
|
return bool(re.search(r'PRIMARY KEY', line))
|
||||||
|
|
||||||
|
searching_for_end = False
|
||||||
|
for line in fileinput.input():
|
||||||
|
if this_line_is_useless(line):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# this line was necessary because ''); was getting
|
||||||
|
# converted (inappropriately) to \');
|
||||||
|
if re.match(r".*, ''\);", line):
|
||||||
|
line = re.sub(r"''\);", r'``);', line)
|
||||||
|
|
||||||
|
if re.match(r'^CREATE TABLE.*', line):
|
||||||
|
searching_for_end = True
|
||||||
|
|
||||||
|
m = re.search('CREATE TABLE "?([a-zA-Z_]*)"?(.*)', line)
|
||||||
|
if m:
|
||||||
|
name, sub = m.groups()
|
||||||
|
line = "DROP TABLE IF EXISTS %(name)s;\nCREATE TABLE IF NOT EXISTS `%(name)s`%(sub)s\n"
|
||||||
|
line = line % dict(name=name, sub=sub)
|
||||||
|
else:
|
||||||
|
m = re.search('INSERT INTO "([a-zA-Z_]*)"(.*)', line)
|
||||||
|
if m:
|
||||||
|
line = 'INSERT INTO %s%s\n' % m.groups()
|
||||||
|
line = line.replace('"', r'\"')
|
||||||
|
line = line.replace('"', "'")
|
||||||
|
line = re.sub(r"([^'])'t'(.)", "\1THIS_IS_TRUE\2", line)
|
||||||
|
line = line.replace('THIS_IS_TRUE', '1')
|
||||||
|
line = re.sub(r"([^'])'f'(.)", "\1THIS_IS_FALSE\2", line)
|
||||||
|
line = line.replace('THIS_IS_FALSE', '0')
|
||||||
|
|
||||||
|
# Add auto_increment if it's not there since sqlite auto_increments ALL
|
||||||
|
# primary keys
|
||||||
|
if searching_for_end:
|
||||||
|
if re.search(r"integer(?:\s+\w+)*\s*PRIMARY KEY(?:\s+\w+)*\s*,", line):
|
||||||
|
line = line.replace("PRIMARY KEY", "PRIMARY KEY AUTO_INCREMENT")
|
||||||
|
# replace " and ' with ` because mysql doesn't like quotes in CREATE commands
|
||||||
|
if line.find('DEFAULT') == -1:
|
||||||
|
line = line.replace(r'"', r'`').replace(r"'", r'`')
|
||||||
|
else:
|
||||||
|
parts = line.split('DEFAULT')
|
||||||
|
parts[0] = parts[0].replace(r'"', r'`').replace(r"'", r'`')
|
||||||
|
line = 'DEFAULT'.join(parts)
|
||||||
|
|
||||||
|
# And now we convert it back (see above)
|
||||||
|
if re.match(r".*, ``\);", line):
|
||||||
|
line = re.sub(r'``\);', r"'');", line)
|
||||||
|
|
||||||
|
if searching_for_end and re.match(r'.*\);', line):
|
||||||
|
searching_for_end = False
|
||||||
|
|
||||||
|
if re.match(r"CREATE INDEX", line):
|
||||||
|
line = re.sub('"', '`', line)
|
||||||
|
|
||||||
|
print line,
|
100
export_dictionary.php
Normal file
100
export_dictionary.php
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
CAUTION!
|
||||||
|
This file is to be run once, only when you've got
|
||||||
|
a complete map as it overwrites blocks*.inc files!
|
||||||
|
It's purpose is to make initial files for you to modify.
|
||||||
|
|
||||||
|
Make sure to back up those after you've done some changes to them!
|
||||||
|
*/
|
||||||
|
include('mapreader.php'); // include map-parsing functions
|
||||||
|
|
||||||
|
// BEGIN CONFIG HERE
|
||||||
|
$mysqlConn=array(); // mysql config data here
|
||||||
|
$mysqlConn['host']="dbhost here";
|
||||||
|
$mysqlConn['user']="dbuser here";
|
||||||
|
$mysqlConn["pass"]="dbpass here";
|
||||||
|
$mysqlConn['base']="dbname here";
|
||||||
|
$mysqlConn['table']="blocks"; // table named the same as Minetest's one
|
||||||
|
|
||||||
|
$divider=100; // How many chunks to fetch at a time? Tinker with this to improve performance.
|
||||||
|
// END CONFIG HERE
|
||||||
|
|
||||||
|
$dictionary=array(); // we will store blocks' names here
|
||||||
|
|
||||||
|
$file1=dirname(__FILE__).'/blocks.inc';
|
||||||
|
$file2=dirname(__FILE__).'/blocks_textures.inc';
|
||||||
|
prepareFile($file1); // prepare those two suckers!
|
||||||
|
prepareFile($file2);
|
||||||
|
|
||||||
|
// Open the database connection
|
||||||
|
// Note: Can be sqlite3 functions here, but I'll stick with mysql. For reasons.
|
||||||
|
$conn=mysql_connect($mysqlConn['host'],$mysqlConn['user'],$mysqlConn['pass']);
|
||||||
|
mysql_select_db($mysqlConn['base']);
|
||||||
|
|
||||||
|
// How many chunks are there in the set?
|
||||||
|
$sql="select count(pos) as count_pos from ".$mysqlConn['table'];
|
||||||
|
$result=mysql_fetch_assoc(mysql_query($sql));
|
||||||
|
$count=$result["count_pos"];
|
||||||
|
|
||||||
|
$countDiv=(int)($count/$divider);
|
||||||
|
|
||||||
|
// Main loop
|
||||||
|
for($i=0;$i<=$countDiv;$i++)
|
||||||
|
{
|
||||||
|
// Indices for the loop to use
|
||||||
|
$start=$i*100;
|
||||||
|
$end=$start+100;
|
||||||
|
// Eyecandy line!
|
||||||
|
print("Reading chunks ".$start." to ".$end." of ".$count." total\n".count($dictionary)." entries so far...\n");
|
||||||
|
// Neat way of doing things. Read $divider number of chunks.
|
||||||
|
$sql="select pos,data from ".$mysqlConn['table']." order by pos asc limit ".$divider." offset ".$start;
|
||||||
|
$result=mysql_query($sql);
|
||||||
|
while($row=mysql_fetch_assoc($result))
|
||||||
|
{
|
||||||
|
$decodedchunk=new Mapreader($row["data"]); // Pass the data to the parser
|
||||||
|
$decodedchunk->exportScenery(); // Needed for the parser to run
|
||||||
|
$mappings=$decodedchunk->exportMappings(); // Export mappings - nodes' names
|
||||||
|
foreach($mappings as $row)
|
||||||
|
{
|
||||||
|
// Filter out some of them - they won't appear on the image either.
|
||||||
|
if($row!="ignore")
|
||||||
|
if($row!="air")
|
||||||
|
{
|
||||||
|
addEntry($row); // Add to the dictionary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($decodedchunk); // Free some memory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now we just write the files
|
||||||
|
$fhandler1=fopen($file1,"wb");
|
||||||
|
$fhandler2=fopen($file2,"wb");
|
||||||
|
foreach($dictionary as $row)
|
||||||
|
{
|
||||||
|
// Povray-compatible syntax. Defaluts to a box with empty texture.
|
||||||
|
fwrite($fhandler1,"#declare ".$row." = box { <0,0,0> <1,1,1> }\n");
|
||||||
|
fwrite($fhandler2,"#declare texture_".$row." = \ntexture {\n\n}\n");
|
||||||
|
}
|
||||||
|
fclose($fhandler1);
|
||||||
|
fclose($fhandler2);
|
||||||
|
|
||||||
|
// Close the database
|
||||||
|
mysql_close($conn);
|
||||||
|
|
||||||
|
function addEntry($entry)
|
||||||
|
{
|
||||||
|
global $dictionary;
|
||||||
|
$data=str_replace(":","_",$entry); // Remove colon, as PovRAY could have problems with it
|
||||||
|
$dictionary[$data]=$data; // Simplest possible way of writing the data without checking if it exists already
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepareFile($file)
|
||||||
|
{
|
||||||
|
unlink($file); // Here we jsut delete files and make new ones.
|
||||||
|
$fhandler=fopen($file,"wb");
|
||||||
|
fclose($fhandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
268
mapreader.php
Normal file
268
mapreader.php
Normal file
@ -0,0 +1,268 @@
|
|||||||
|
<?php
|
||||||
|
class Mapreader
|
||||||
|
{
|
||||||
|
private $data; // dane do obrobienia
|
||||||
|
|
||||||
|
private $index=0; // indeks do walkera - ktora pare czytamy
|
||||||
|
|
||||||
|
public $mapVersion; // wersja mapy
|
||||||
|
private $bitmask=array(1=>0,2=>0,4=>0,8=>0); // flagi - is_underground, day_night_differs, lighting_expired, generated
|
||||||
|
private $contentWidth; // szerokosc danych param0 wezla
|
||||||
|
private $paramsWidth; // szerokosc danych wezlow
|
||||||
|
private $databinary; // dane do obrobienia przekodowane na binarke
|
||||||
|
private $gzipoffsets=array(); // offsety spakowanych blokow
|
||||||
|
private $map=array();
|
||||||
|
private $mappings=array();
|
||||||
|
|
||||||
|
|
||||||
|
function __construct($input)
|
||||||
|
{
|
||||||
|
// konstruktor - bierze na siebie jedna linie (jeden chunk)
|
||||||
|
$this->data=$input;
|
||||||
|
$this->recodeInput();
|
||||||
|
unset($input);
|
||||||
|
$this->versionSet();
|
||||||
|
$this->bitflagsSet();
|
||||||
|
$this->contentwidthSet();
|
||||||
|
$this->paramswidthSet();
|
||||||
|
$this->gzipoffsets=$this->findGzipOffsets();
|
||||||
|
$this->splitCompressedBlocks();
|
||||||
|
//$this->exportScenery(); // do wywolania z zewnatrz
|
||||||
|
//print_r($this->databinary);
|
||||||
|
|
||||||
|
/*
|
||||||
|
print("\nwersja mapy: ".$this->mapVersion."\n");
|
||||||
|
print("\nflagi: 1:".$this->bitmask[1]." 2:".$this->bitmask[2]." 4:".$this->bitmask[4]." 8:".$this->bitmask[8]."\n");
|
||||||
|
print("\nwielkosc param0: ".$this->contentWidth."\n");
|
||||||
|
print("\nwielkosc parametrow: ".$this->paramsWidth."\n");
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
function __destruct()
|
||||||
|
{
|
||||||
|
unset($this->mapVersion);
|
||||||
|
unset($this->index);
|
||||||
|
unset($this->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function readlen($input)
|
||||||
|
{
|
||||||
|
// podaj dlugosc ciagu w bajtach - 2 znaki hex
|
||||||
|
return(strlen($input));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function versionSet()
|
||||||
|
{
|
||||||
|
// ustawia zmienna wersji mapy
|
||||||
|
$this->mapVersion=$this->readByte(0); // 0 to pozycja wersji
|
||||||
|
}
|
||||||
|
|
||||||
|
private function bitflagsSet()
|
||||||
|
{
|
||||||
|
$bf=$this->readByte(1); // 1 to pozycja flag
|
||||||
|
$this->bitmask[1]=$bf&1;
|
||||||
|
$this->bitmask[2]=($bf&2)>>1;
|
||||||
|
$this->bitmask[4]=($bf&4)>>2;
|
||||||
|
$this->bitmask[8]=($bf&8)>>3;
|
||||||
|
unset($bf);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function contentwidthSet()
|
||||||
|
{
|
||||||
|
// ustawia zmienna szerokosci param0
|
||||||
|
$this->contentWidth=$this->readByte(2); // 0 to pozycja wersji
|
||||||
|
}
|
||||||
|
|
||||||
|
private function paramswidthSet()
|
||||||
|
{
|
||||||
|
// ustawia zmienna szerokosci parametrow
|
||||||
|
$this->paramsWidth=$this->readByte(3); // 0 to pozycja wersji
|
||||||
|
}
|
||||||
|
|
||||||
|
private function findGzipOffsets()
|
||||||
|
{
|
||||||
|
$offset=array();
|
||||||
|
$j=$this->readlen($this->data)-2;
|
||||||
|
for($i=0;$i<$j;$i++)
|
||||||
|
{
|
||||||
|
if($this->readByte($i)==120) // 0x78
|
||||||
|
{
|
||||||
|
if($this->readByte($i+1)==156) // 0x9c
|
||||||
|
{
|
||||||
|
$offset[1]=$i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
for($k=$i;$k<$j;$k++)
|
||||||
|
{
|
||||||
|
if($this->readByte($k)==120)
|
||||||
|
{
|
||||||
|
if($this->readByte($k+1)==156)
|
||||||
|
{
|
||||||
|
$offset[2]=$k;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return($offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function recodeInput()
|
||||||
|
{
|
||||||
|
$temp='';
|
||||||
|
$j=$this->readlen($this->data);
|
||||||
|
for($i=4;$i<$j;$i++)
|
||||||
|
{
|
||||||
|
$temp.=chr($this->readByte($i));
|
||||||
|
}
|
||||||
|
$this->databinary=$temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function splitCompressedBlocks()
|
||||||
|
{
|
||||||
|
$temp='';
|
||||||
|
$j=$this->readlen($this->data);
|
||||||
|
$g1='/tmp/map';
|
||||||
|
$tempfile=fopen($g1, "wb");
|
||||||
|
$k=$this->gzipoffsets[2];
|
||||||
|
for($i=4;$i<$k;$i++)
|
||||||
|
{
|
||||||
|
fwrite($tempfile,chr($this->readByte($i)));
|
||||||
|
//pack('n',$this->readByte($i)));
|
||||||
|
}
|
||||||
|
fclose($tempfile);
|
||||||
|
$g2='/tmp/dict';
|
||||||
|
$tempfile=fopen($g2, "wb");
|
||||||
|
$k=$this->gzipoffsets[2];
|
||||||
|
for($i=$k;$i<$j;$i++)
|
||||||
|
{
|
||||||
|
fwrite($tempfile,chr($this->readByte($i)));
|
||||||
|
//pack('n',$this->readByte($i)));
|
||||||
|
}
|
||||||
|
fclose($tempfile);
|
||||||
|
|
||||||
|
system(dirname(__FILE__).'/unzlib.py');
|
||||||
|
|
||||||
|
// wczytanie mapy
|
||||||
|
$this->loadMap($g1.'.uncompressed',$g2.'.uncompressed','/tmp/leftover.uncompressed');
|
||||||
|
|
||||||
|
//var_dump(gzinflate(readfile($g)));
|
||||||
|
|
||||||
|
/*$gz = gzopen($g, 'r');
|
||||||
|
while (!gzeof($gz)) {
|
||||||
|
echo gzgetc($gz).'.';
|
||||||
|
}
|
||||||
|
gzclose($gz);/**/
|
||||||
|
//unlink($g);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function loadMap($g1,$g2,$g3)
|
||||||
|
{
|
||||||
|
$mapfile=fopen($g1, "rb");
|
||||||
|
// czytamy: 4096*u16, 4096*u8, 4096*u8
|
||||||
|
// dane są msb-first
|
||||||
|
for($i=0;$i<4096;$i++)
|
||||||
|
{
|
||||||
|
$this->map[$i]['param0']=ord(fread($mapfile,1))*256+ord(fread($mapfile,1));
|
||||||
|
}
|
||||||
|
for($i=0;$i<4096;$i++)
|
||||||
|
{
|
||||||
|
$this->map[$i]['param1']=ord(fread($mapfile,1));
|
||||||
|
}
|
||||||
|
for($i=0;$i<4096;$i++)
|
||||||
|
{
|
||||||
|
$this->map[$i]['param2']=ord(fread($mapfile,1));
|
||||||
|
}
|
||||||
|
fclose($mapfile);
|
||||||
|
// wczytane, porzadkujemy
|
||||||
|
|
||||||
|
$leftover=fopen($g3, "rb");
|
||||||
|
fread($leftover,1); // wczytaj static_object_version (nie jest potrzebne)
|
||||||
|
$socount=(ord(fread($leftover,1))*256)+ord(fread($leftover,1)); // ile jest static objects
|
||||||
|
//print("\n\nilosc static objects: ".$socount."\n\n"); //
|
||||||
|
while($socount!=0)
|
||||||
|
{
|
||||||
|
fread($leftover,13); // czytamy rekordy zeby sie przesunac w pliku
|
||||||
|
$datasize=(ord(fread($leftover,1))*256)+ord(fread($leftover,1)); // czytamy datasize
|
||||||
|
if($datasize!=0)
|
||||||
|
fread($leftover,$datasize); // czytamy tyle bajtow ile bylo w datasize
|
||||||
|
$socount--;
|
||||||
|
}
|
||||||
|
fread($leftover,4); // czytamy timestamp (i olewamy go)
|
||||||
|
$ver=ord(fread($leftover,1));
|
||||||
|
//print('wersja name-id-mapping: '.$ver."\n\n"); // czytamy name-id-mapping-version (z zalozenia zero)
|
||||||
|
$numofmappings=(ord(fread($leftover,1))*256)+ord(fread($leftover,1)); // czytamy ile jest mapowan
|
||||||
|
//print('znalazlem '.$numofmappings." mapowan\n\n");
|
||||||
|
while($numofmappings!=0)
|
||||||
|
{
|
||||||
|
$id=(ord(fread($leftover,1))*256)+ord(fread($leftover,1)); // wczytujemy id mapowania
|
||||||
|
$namelen=(ord(fread($leftover,1))*256)+ord(fread($leftover,1)); // wczytujemy dlugosc nazwy
|
||||||
|
$this->mappings[$id]=fread($leftover,$namelen);
|
||||||
|
$numofmappings--;
|
||||||
|
}
|
||||||
|
fclose($leftover);
|
||||||
|
// zostalo: dict.uncompressed - napisy itp
|
||||||
|
|
||||||
|
$this->matchMappings();
|
||||||
|
|
||||||
|
|
||||||
|
//debug
|
||||||
|
//print_r($this->mappings);
|
||||||
|
//print_r($this->map);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function matchMappings()
|
||||||
|
{
|
||||||
|
for($i=0;$i<4096;$i++)
|
||||||
|
{
|
||||||
|
$index=$this->map[$i]["param0"];
|
||||||
|
$id=$this->mappings[$index];
|
||||||
|
$this->map[$i]["param0"]=$id;
|
||||||
|
}
|
||||||
|
$x=0;
|
||||||
|
$y=0;
|
||||||
|
$z=0;
|
||||||
|
for($x=0;$x<16;$x++)
|
||||||
|
{
|
||||||
|
for($y=0;$y<16;$y++)
|
||||||
|
{
|
||||||
|
for($z=0;$z<16;$z++)
|
||||||
|
{
|
||||||
|
$i=$x+($y*16)+($z*16*16);
|
||||||
|
$this->map[$x][$y][$z]=$this->map[$i];
|
||||||
|
//unset($this->map[$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function exportScenery()
|
||||||
|
{
|
||||||
|
//print_r($this->map);
|
||||||
|
for($i=16;$i<4096;$i++)
|
||||||
|
{
|
||||||
|
unset($this->map[$i]);
|
||||||
|
}
|
||||||
|
$this->map["bits"][1]=$this->bitmask[1];
|
||||||
|
$this->map["bits"][2]=$this->bitmask[2];
|
||||||
|
$this->map["bits"][4]=$this->bitmask[4];
|
||||||
|
$this->map["bits"][8]=$this->bitmask[8];
|
||||||
|
return($this->map);
|
||||||
|
}
|
||||||
|
|
||||||
|
function exportMappings()
|
||||||
|
{
|
||||||
|
return($this->mappings);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function readByte($i)
|
||||||
|
{
|
||||||
|
// zwroc bajt z pozycji danej przez index
|
||||||
|
$a=$i;
|
||||||
|
return(ord($this->data[$a]));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
115
povrayfunctions.php
Normal file
115
povrayfunctions.php
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
<?php
|
||||||
|
function makeChunkInPovray($scenerydata,$filename,$chunkx,$chunky,$chunkz)
|
||||||
|
{
|
||||||
|
$deltax=16*$chunkx;
|
||||||
|
$deltay=16*$chunky;
|
||||||
|
$deltaz=16*$chunkz;
|
||||||
|
//$tresc='';
|
||||||
|
if(true)//$scenerydata["bits"][8]!=0)
|
||||||
|
{
|
||||||
|
for($z=0;$z<16;$z++)
|
||||||
|
{
|
||||||
|
for($y=0;$y<16;$y++)
|
||||||
|
{
|
||||||
|
for($x=0;$x<16;$x++)
|
||||||
|
{
|
||||||
|
if($scenerydata[$x][$y][$z]["param0"]!='air')
|
||||||
|
if($scenerydata[$x][$y][$z]["param0"]!='ignore')
|
||||||
|
{
|
||||||
|
$tresc="object { mycube translate <";
|
||||||
|
file_put_contents($filename,$tresc,FILE_APPEND|LOCK_EX);
|
||||||
|
$tresc=(string)($x+$deltax);
|
||||||
|
file_put_contents($filename,$tresc,FILE_APPEND|LOCK_EX);
|
||||||
|
$tresc=",";
|
||||||
|
file_put_contents($filename,$tresc,FILE_APPEND|LOCK_EX);
|
||||||
|
$tresc=(string)($z+$deltaz);
|
||||||
|
file_put_contents($filename,$tresc,FILE_APPEND|LOCK_EX);
|
||||||
|
$tresc=",";
|
||||||
|
file_put_contents($filename,$tresc,FILE_APPEND|LOCK_EX);
|
||||||
|
$tresc=(string)($y+$deltay);
|
||||||
|
file_put_contents($filename,$tresc,FILE_APPEND|LOCK_EX);
|
||||||
|
$tresc="> texture {";
|
||||||
|
file_put_contents($filename,$tresc,FILE_APPEND|LOCK_EX);
|
||||||
|
if($scenerydata[$x][$y][$z]["param0"]=="default:stone")
|
||||||
|
{
|
||||||
|
$tresc="T_Stone24";
|
||||||
|
}
|
||||||
|
elseif($scenerydata[$x][$y][$z]["param0"]=="default:sand")
|
||||||
|
{
|
||||||
|
$tresc="default_sand";
|
||||||
|
}
|
||||||
|
elseif($scenerydata[$x][$y][$z]["param0"]=="wool:blue")
|
||||||
|
{
|
||||||
|
$tresc="wool_blue";
|
||||||
|
}
|
||||||
|
elseif($scenerydata[$x][$y][$z]["param0"]=="wool:green")
|
||||||
|
{
|
||||||
|
$tresc="wool_green";
|
||||||
|
}
|
||||||
|
elseif($scenerydata[$x][$y][$z]["param0"]=="wool:yellow")
|
||||||
|
{
|
||||||
|
$tresc="wool_yellow";
|
||||||
|
}
|
||||||
|
elseif($scenerydata[$x][$y][$z]["param0"]=="wool:red")
|
||||||
|
{
|
||||||
|
$tresc="wool_red";
|
||||||
|
}
|
||||||
|
elseif($scenerydata[$x][$y][$z]["param0"]=="wool:cyan")
|
||||||
|
{
|
||||||
|
$tresc="wool_cyan";
|
||||||
|
}
|
||||||
|
elseif($scenerydata[$x][$y][$z]["param0"]=="wool:pink")
|
||||||
|
{
|
||||||
|
$tresc="wool_pink";
|
||||||
|
}
|
||||||
|
elseif($scenerydata[$x][$y][$z]["param0"]=="wool:brown")
|
||||||
|
{
|
||||||
|
$tresc="wool_brown";
|
||||||
|
}
|
||||||
|
elseif($scenerydata[$x][$y][$z]["param0"]=="wool:orange")
|
||||||
|
{
|
||||||
|
$tresc="wool_orange";
|
||||||
|
}
|
||||||
|
elseif($scenerydata[$x][$y][$z]["param0"]=="wool:magenta")
|
||||||
|
{
|
||||||
|
$tresc="wool_magenta";
|
||||||
|
}
|
||||||
|
elseif($scenerydata[$x][$y][$z]["param0"]=="technic:concrete")
|
||||||
|
{
|
||||||
|
$tresc="technic_concrete";
|
||||||
|
}
|
||||||
|
elseif($scenerydata[$x][$y][$z]["param0"]=="technic:stainless_steel_block")
|
||||||
|
{
|
||||||
|
$tresc="T_Chrome_3C normal{granite scale<100, 0.1, 0.1>}";
|
||||||
|
}
|
||||||
|
elseif($scenerydata[$x][$y][$z]["param0"]=="default:water")
|
||||||
|
{
|
||||||
|
$tresc="default_water";
|
||||||
|
}
|
||||||
|
elseif($scenerydata[$x][$y][$z]["param0"]=="default:water_source")
|
||||||
|
{
|
||||||
|
$tresc="default_water";
|
||||||
|
}
|
||||||
|
elseif($scenerydata[$x][$y][$z]["param0"]=="default:dirt_with_grass")
|
||||||
|
{
|
||||||
|
$tresc="default_dirt_with_grass";
|
||||||
|
}
|
||||||
|
elseif($scenerydata[$x][$y][$z]["param0"]=="default:dirt")
|
||||||
|
{
|
||||||
|
$tresc="default_dirt";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$tresc="pigment{ color rgbf<1,1,1,0.5>}";
|
||||||
|
}
|
||||||
|
file_put_contents($filename,$tresc,FILE_APPEND|LOCK_EX);
|
||||||
|
$tresc="} }\n\n";
|
||||||
|
file_put_contents($filename,$tresc,FILE_APPEND|LOCK_EX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
1
render_anim.sh
Executable file
1
render_anim.sh
Executable file
@ -0,0 +1 @@
|
|||||||
|
screen -m -S povray povray scenery.pov +Q9 +W1920 +H1080
|
1
render_preview.sh
Executable file
1
render_preview.sh
Executable file
@ -0,0 +1 @@
|
|||||||
|
screen -m -S povray povray scenery.pov +Q9 +W1920 +H1080 +KI0.0 +KF1.0 +KFI0 +KFF1799 +KC
|
22
unpack_coords.py
Executable file
22
unpack_coords.py
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def getIntegerAsBlock(i):
|
||||||
|
x = unsignedToSigned(i % 4096, 2048)
|
||||||
|
i = int((i - x) / 4096)
|
||||||
|
y = unsignedToSigned(i % 4096, 2048)
|
||||||
|
i = int((i - y) / 4096)
|
||||||
|
z = unsignedToSigned(i % 4096, 2048)
|
||||||
|
print str(x) + ' ' + str(y) + ' ' + str(z)
|
||||||
|
# return x,y,z
|
||||||
|
|
||||||
|
def unsignedToSigned(i, max_positive):
|
||||||
|
if i < max_positive:
|
||||||
|
return i
|
||||||
|
else:
|
||||||
|
return i - 2*max_positive
|
||||||
|
|
||||||
|
a = int(sys.argv[1])
|
||||||
|
|
||||||
|
getIntegerAsBlock(a)
|
23
unzlib.py
Executable file
23
unzlib.py
Executable file
@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
|
||||||
|
import zlib
|
||||||
|
import sys
|
||||||
|
|
||||||
|
str_object1 = open('/tmp/map', 'rb').read()
|
||||||
|
str_object2 = zlib.decompress(str_object1)
|
||||||
|
f = open('/tmp/map.uncompressed', 'wb')
|
||||||
|
f.write(str_object2)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
str_object1 = open('/tmp/dict', 'rb').read()
|
||||||
|
str_object2 = zlib.decompress(str_object1)
|
||||||
|
f = open('/tmp/dict.uncompressed', 'wb')
|
||||||
|
f.write(str_object2)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
decom = zlib.decompressobj()
|
||||||
|
d = decom.decompress(str_object1)
|
||||||
|
str_object3 = decom.unused_data
|
||||||
|
f = open('/tmp/leftover.uncompressed', 'wb')
|
||||||
|
f.write(str_object3)
|
||||||
|
f.close()
|
Loading…
x
Reference in New Issue
Block a user