From 420eeee620a287ac5bf133f8a17329a7182d5bbf Mon Sep 17 00:00:00 2001 From: epoch Date: Tue, 5 Feb 2019 21:48:29 -0600 Subject: forgot to add bin dir that contains a LOT of the handy stuff --- bin/dat2hackvr.pl | 34 +++++++++++++++++++++++++ bin/embolden | 42 +++++++++++++++++++++++++++++++ bin/gnuplot_hackvr.gplot | 7 ++++++ bin/gnuplot_obj.gplot | 7 ++++++ bin/hackvr2dat.sh | 2 ++ bin/line2hackvr.sh | 12 +++++++++ bin/makelabel.sh | 37 ++++++++++++++++++++++++++++ bin/map2globe.py | 59 ++++++++++++++++++++++++++++++++++++++++++++ bin/obj2dat.pl | 41 +++++++++++++++++++++++++++++++ bin/obj2hackvr.pl | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ bin/obj2hackvr2.pl | 50 +++++++++++++++++++++++++++++++++++++ bin/offsetshape.sh | 5 ++++ 12 files changed, 360 insertions(+) create mode 100755 bin/dat2hackvr.pl create mode 100644 bin/embolden create mode 100644 bin/gnuplot_hackvr.gplot create mode 100644 bin/gnuplot_obj.gplot create mode 100644 bin/hackvr2dat.sh create mode 100755 bin/line2hackvr.sh create mode 100755 bin/makelabel.sh create mode 100755 bin/map2globe.py create mode 100755 bin/obj2dat.pl create mode 100755 bin/obj2hackvr.pl create mode 100755 bin/obj2hackvr2.pl create mode 100755 bin/offsetshape.sh 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=) { + 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() { + 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() { + $_ =~ 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() { + 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;}' -- cgit v1.2.3