summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorepoch <epoch@hacking.allowed.org>2019-02-05 21:48:29 -0600
committerepoch <epoch@hacking.allowed.org>2019-02-05 21:48:29 -0600
commit420eeee620a287ac5bf133f8a17329a7182d5bbf (patch)
tree407cd59748e0e5ef4f88b15305dd303aa64cf8da /bin
parent848a823b1287d8804e8d6170c3ca30ccf7689784 (diff)
downloadhackvr-420eeee620a287ac5bf133f8a17329a7182d5bbf.tar.gz
hackvr-420eeee620a287ac5bf133f8a17329a7182d5bbf.zip
forgot to add bin dir that contains a LOT of the handy stuff
Diffstat (limited to 'bin')
-rwxr-xr-xbin/dat2hackvr.pl34
-rw-r--r--bin/embolden42
-rw-r--r--bin/gnuplot_hackvr.gplot7
-rw-r--r--bin/gnuplot_obj.gplot7
-rw-r--r--bin/hackvr2dat.sh2
-rwxr-xr-xbin/line2hackvr.sh12
-rwxr-xr-xbin/makelabel.sh37
-rwxr-xr-xbin/map2globe.py59
-rwxr-xr-xbin/obj2dat.pl41
-rwxr-xr-xbin/obj2hackvr.pl64
-rwxr-xr-xbin/obj2hackvr2.pl50
-rwxr-xr-xbin/offsetshape.sh5
12 files changed, 360 insertions, 0 deletions
diff --git a/bin/dat2hackvr.pl b/bin/dat2hackvr.pl
new file mode 100755
index 0000000..03c5315
--- /dev/null
+++ b/bin/dat2hackvr.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+
+use strict;
+
+die "usage: dat2hackvr.pl name file\n" unless $ARGV[0];
+
+my $line;
+my $prev;
+my $first;
+open(FILE,$ARGV[1]) if $ARGV[1];
+while($line=<FILE>) {
+ chomp $line;
+ if(!($line =~ m/^#/)) {
+ if($line eq "") {
+# print $ARGV[0];
+# print " addtriangle ";
+# print $prev . " 0 " . $first . " 0 " . $first . " 0";
+# print "\n";
+ $first="";
+ } else {
+ if($prev ne "") {
+ print $ARGV[0];
+ print " addshape 2 2 ";
+ print $line . " 0 " . $prev . " 0";
+ print "\n";
+ }
+ $prev="";
+ }
+ if($first eq "") {
+ $first=$line;
+ }
+ $prev=$line;
+ }
+}
diff --git a/bin/embolden b/bin/embolden
new file mode 100644
index 0000000..7b1d951
--- /dev/null
+++ b/bin/embolden
@@ -0,0 +1,42 @@
+/*
+
+so, we have a line.
+
+from 0,0 to 10,0
+
+and we want it to transform into a rectangle at about...
+
+-1,-1 1,-1 1,11 -1,11
+
+I guess we're taking each point and pushing it away from itself.
+
+so 0,0... we can make into a square. we need to push in a direction based on the direction of the other half of the line
+
+so a=points_to_angle(p1,p2)
+
+which is 90deg in this case from 0,0 to 10,0
+and we need to push 0,0 in two directions to create two new points
+at angles...
+90+135 and 90+135+90
+
+a+135 and a+135+90
+
+now to pick an emboldeness amount. sqrt(2) will get us to the original points I guessed at earlier.
+
+#define embolden(p1,p2,angle,dist)
+
+if(s.len == 2) {
+ a1=points_to_angle(p1,p2);
+ a2=points_to_angle(p2,p1);
+ d=1;//how far to embolden
+ //a2 = (a1 + 180) % 360
+ s[0]=c3_add(s.p[0],(c3_t){sin(a2+45)*d,cos(a2+45)*d,0})
+ s[1]=c3_add(s.p[0],(c3_t){sin(a2-45)*d,cos(a2-45)*d,0})
+ s[2]=c3_add(s.p[1],(c3_t){sin(a1+45)*d,cos(a1+45)*d,0})
+ s[3]=c3_add(s.p[1],(c3_t){sin(a1-45)*d,cos(a1-45)*d,0})
+}
+
+//this can be a script. it'll turn lines into rectangles.
+//could be done with awk probably.
+//base it on offsetshape?
+//maybe just do it in python.
diff --git a/bin/gnuplot_hackvr.gplot b/bin/gnuplot_hackvr.gplot
new file mode 100644
index 0000000..cafb729
--- /dev/null
+++ b/bin/gnuplot_hackvr.gplot
@@ -0,0 +1,7 @@
+set terminal x11
+set xrange[-16:16]
+set yrange[-16:16]
+set zrange[-16:16]
+splot '< cat ../meshes/bowser.hackvr | bash ./hackvr2dat.sh' with lines
+pause 1
+reread
diff --git a/bin/gnuplot_obj.gplot b/bin/gnuplot_obj.gplot
new file mode 100644
index 0000000..0b5a807
--- /dev/null
+++ b/bin/gnuplot_obj.gplot
@@ -0,0 +1,7 @@
+set terminal sixelgd
+set xrange[-16:16]
+set yrange[-16:16]
+set zrange[-16:16]
+splot '< ./obj2dat.pl ../meshes/female_basemesh1_2.obj' with lines
+pause 1
+reread
diff --git a/bin/hackvr2dat.sh b/bin/hackvr2dat.sh
new file mode 100644
index 0000000..295de4a
--- /dev/null
+++ b/bin/hackvr2dat.sh
@@ -0,0 +1,2 @@
+### just split into points for each line and and add two blank lines after each hackvr line
+tr -s ' ' | cut '-d ' -f5- | sed 's/$/__/g' | tr ' ' '\n' | paste - - - | tr '_' '\n'
diff --git a/bin/line2hackvr.sh b/bin/line2hackvr.sh
new file mode 100755
index 0000000..7128026
--- /dev/null
+++ b/bin/line2hackvr.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+#this is used on turn2line output
+USAGE="usage: line2hackvr.sh name < turn2line-output"
+if [ "_$1" = '_' ];then
+ echo $USAGE >&2
+ exit 1
+fi
+if [ "_$1" = "_-h" -o "_$1" = "_--help" -o "_$1" = "_-help" ];then
+ echo $USAGE
+ exit 0
+fi
+xargs -L 1 printf "%s addshape 2 2 0 %d %d 0 %d %d\n" "$1" $line
diff --git a/bin/makelabel.sh b/bin/makelabel.sh
new file mode 100755
index 0000000..aa6a811
--- /dev/null
+++ b/bin/makelabel.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+USAGE="usage: makelabel.sh labelname x y z < labelcontent"
+target="$1"
+xoffset=$2
+yoffset=$3
+zoffset=$4
+if [ "_$PREFIX" = "_" ];then
+ echo '$PREFIX' is not set. I use this to find where my font files are stored.
+ exit 1
+fi
+if [ "_$1" = "_-h" -o "_$1" = "_--help" -o "_$1" = "_-help" ];then
+ echo $USAGE
+ exit 0 #we were asked for help and we succeeded with supplying help. :)
+fi
+if [ "_" = "_$1" -o "_" = "_$2" -o "_" = "_$3" -o "_" = "_$4" ];then
+ echo "something is not right. maybe this will help:" >&2
+ echo $USAGE >&2
+ exit 1 #something fucked up, but let's tell them how they should have done it.
+fi
+if grep ' ' <<<$1;then
+ echo 'fuck. no spaces in $1.'
+ exit 1
+fi
+##target should not have any spaces or else it fucks shit up. >_>... oh well. hex encode it.
+while read -rN 1 c;do
+ name="$(printf "%02x" "'$c")"
+ if [ "$name" = "0a" ]; then
+ xoffset=-6
+ yoffset="$(printf '%d - %d\n' $yoffset 10 | bc)"
+ fi
+ if grep "^$name " ${PREFIX}/share/hackvr/font/font.hackvr 2>&1 > /dev/null;then #don't do this shit unless we actually have something to draw. awk in offsetshape bitches when there's nothing.
+ grep "^$name " ${PREFIX}/share/hackvr/font.hackvr \
+ | sed 's/^'"$name"'/'"$target"'/' \
+ | offsetshape.sh "$xoffset" "$yoffset" "$zoffset"
+ fi
+ xoffset="$(printf '%d + %d\n' $xoffset 6 | bc)"
+done
diff --git a/bin/map2globe.py b/bin/map2globe.py
new file mode 100755
index 0000000..cb49675
--- /dev/null
+++ b/bin/map2globe.py
@@ -0,0 +1,59 @@
+#!/usr/bin/python3.6
+
+import sys
+import math
+
+plat=0
+plon=0
+lat=0
+lon=0
+x="0"
+y="0"
+z="0"
+
+#lon goes from -180 to +180
+#lat goes from -90 to +90
+# / 90 * math.pi
+#they need to be in the range 0 to 2pi?
+
+if(len(sys.argv) < 2):
+ sys.stderr.write("usage: map2globe.py name < map.dat\n")
+ sys.exit(1)
+
+name=sys.argv[1]
+
+print("{} addshape 4 1 0 0 0 1 0 0".format(name))
+rotation=0
+
+while(1):
+ #print (plat,plon,lat,lon)
+ try:
+ line=input()
+ line.strip('\r\n')
+ (lon,lat)=map(float,filter(None,line.split(' ')))
+ slat=(((lat)/180)*math.pi)
+ slon=(((lon)/180)*math.pi)
+ (x,y,z)=map(str,(math.cos(slat)*math.cos(slon), math.sin(slat),math.cos(slat)*math.sin(slon)))
+# (x,y,z)=map(str,(slon,slat,0))
+ except EOFError:
+ print("# reached EOF")
+ break
+ except ValueError:
+ #ignore this line
+ print("# read an invalid line: " + line)
+ if(line == ""):
+ (lat,lon,x,y,z)=(0,0,"","","")
+ except:
+ e = sys.exc_info()[0]
+ print("# error: " + str(e))
+ break
+ if(lat and lon and x and y and z and plat and plon and px and py and pz): #if the previouses exist
+ print("{} addshape 2 2 {} {} {} {} {} {}".format(name,x,y,z,px,py,pz))
+ print("{} rotate 0 {} 0".format(name,str(rotation)))
+ rotation+=1
+ rotation%=360
+
+#set previouses to currents
+ (plat,plon,px,py,pz)=(lat,lon,x,y,z)
+
+print("# done")
diff --git a/bin/obj2dat.pl b/bin/obj2dat.pl
new file mode 100755
index 0000000..a1f177e
--- /dev/null
+++ b/bin/obj2dat.pl
@@ -0,0 +1,41 @@
+#!/usr/bin/perl
+
+use strict;
+
+die "usage: obj2dat.pl file\n" unless $ARGV[0];
+
+my $i;
+my $j;
+my $com;
+my @vertices;
+my @faces;
+my @linepart;
+my @parts;
+my @points;
+my @tmp;
+my $tmp;
+my $color=2;
+open(FILE,$ARGV[0]) if $ARGV[0];
+while(<FILE>) {
+ chomp;
+ $_ =~ s/[\r\n]//g;
+ @linepart=split(/ /,$_,2);
+ $com=$linepart[0];
+ if($com eq "v") {
+ push(@vertices,$linepart[1]);
+ }
+ if($com eq "f") {
+ push(@faces,$linepart[1]);
+ }
+}
+
+foreach $tmp (@faces) {
+ @points=split(/ /,$tmp);
+ @points = map { $_ =~ s/\/.+$//g; $_; } @points;
+ for($i=0;$i<(@points);$i++) {
+ print $vertices[$points[$i]-1];
+ print "\n";
+ }
+ print "\n";
+ print "\n";
+}
diff --git a/bin/obj2hackvr.pl b/bin/obj2hackvr.pl
new file mode 100755
index 0000000..3639750
--- /dev/null
+++ b/bin/obj2hackvr.pl
@@ -0,0 +1,64 @@
+#!/usr/bin/perl
+
+use strict;
+
+die "usage: obj2hackvr.pl name file\n" unless $ARGV[0];
+
+my $i;
+my $j;
+my $com;
+my @vertices;
+my @faces;
+my @linepart;
+my @parts;
+my @points;
+my @tmp;
+my $tmp;
+open(FILE,$ARGV[1]) if $ARGV[1];
+while(<FILE>) {
+ $_ =~ s/[\n\r]//g;
+ @linepart=split(/ /,$_,2);
+ $com=$linepart[0];
+ if($com eq "v") {
+ push(@vertices,$linepart[1]);
+ }
+ if($com eq "f") {
+ push(@faces,$linepart[1]);
+ }
+}
+#foreach $tmp (@vertices) {
+# foreach(@$tmp) {
+# print $tmp . "\n";
+# }
+#}
+
+#foreach $tmp (@faces) {
+# @points=split(/ /,$tmp);
+# @points = map { $_ =~ s/\/.+$//g; $_; } @points;
+## print @points;
+# print $ARGV[0];
+# print " addshape ";
+# print @points+0;
+# for($i=0;$i<(@points+0);$i++) {
+# print " ";
+# print $vertices[$points[$i]];
+# }
+# print "\n";
+#}
+
+#convert to triangles
+foreach $tmp (@faces) {
+ @points=split(/ /,$tmp);
+ @points = map { $_ =~ s/\/.+$//g; $_; } @points;
+# print @points;
+ for($i=2;$i<(@points);$i++) {
+ print $ARGV[0];
+ print " addshape 2 3 ";
+ print $vertices[$points[0]-1];
+ print " ";
+ print $vertices[$points[$i-1]-1];
+ print " ";
+ print $vertices[$points[$i]-1];
+ print "\n";
+ }
+}
diff --git a/bin/obj2hackvr2.pl b/bin/obj2hackvr2.pl
new file mode 100755
index 0000000..0736c6d
--- /dev/null
+++ b/bin/obj2hackvr2.pl
@@ -0,0 +1,50 @@
+#!/usr/bin/perl
+
+use strict;
+
+die "usage: obj2hackvr.pl name file\n" unless $ARGV[0];
+
+my $i;
+my $j;
+my $com;
+my @vertices;
+my @faces;
+my @linepart;
+my @parts;
+my @points;
+my @tmp;
+my $tmp;
+my $color=2;
+open(FILE,$ARGV[1]) if $ARGV[1];
+while(<FILE>) {
+ chomp;
+ $_ =~ s/[\r\n]//g;
+ @linepart=split(/ /,$_,2);
+ $com=$linepart[0];
+ if($com eq "v") {
+ push(@vertices,$linepart[1]);
+ }
+ if($com eq "f") {
+ push(@faces,$linepart[1]);
+ }
+}
+
+#foreach $tmp (@vertices) {
+# foreach(@$tmp) {
+# print $tmp . "\n";
+# }
+#}
+
+foreach $tmp (@faces) {
+ @points=split(/ /,$tmp);
+ @points = map { $_ =~ s/\/.+$//g; $_; } @points;
+## print @points;
+ print $ARGV[0];
+ print " addshape " . (rand()*8%8) . " ";
+ print @points+0;
+ for($i=0;$i<(@points);$i++) {
+ print " ";
+ print $vertices[$points[$i]-1];
+ }
+ print "\n";
+}
diff --git a/bin/offsetshape.sh b/bin/offsetshape.sh
new file mode 100755
index 0000000..f3ceabd
--- /dev/null
+++ b/bin/offsetshape.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+#format of lines read from stdin:
+# $1 $2 $3 $4 <-- variables in awk
+#objectname addshape color points_in_shape
+awk '{ for(i=5;i<=(4+($4*3));i+=3){$i+='"$1"';$(i+1)+='"$2"';$(i+2)+='"$3"';} print $0;}'