From 6fc27efe6b094e7b89e59b27a9702e649383644a Mon Sep 17 00:00:00 2001 From: Philipp Kramer Date: Wed, 1 Feb 2023 12:13:40 +0100 Subject: [PATCH] add script --- README.md | 7 ++- panoconfig.py | 122 ++++++++++++++++++++++++++++++++++++++++++ template_hotspots.txt | 9 ++++ template_panellum.txt | 38 +++++++++++++ template_scenes.txt | 11 ++++ 5 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 panoconfig.py create mode 100644 template_hotspots.txt create mode 100644 template_panellum.txt create mode 100644 template_scenes.txt diff --git a/README.md b/README.md index f7e52b8..3e4c378 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ # panellum_generator Configuration generator for Panellum Panorama Viewer. -https://pannellum.org/ \ No newline at end of file +https://pannellum.org/ + +## Usage + +python panoconfig.py input.txt -o index.htm + diff --git a/panoconfig.py b/panoconfig.py new file mode 100644 index 0000000..7359b85 --- /dev/null +++ b/panoconfig.py @@ -0,0 +1,122 @@ +import math +import argparse + +#input config file format: x,y,z,id,filename,angleoffset +#angleoffset is 0 when center of 360 image points to the right, positive rotation means image center in pointing more CCW. value in degrees + +parser = argparse.ArgumentParser( + prog = 'File Edit Script', + description = 'Read content of text file and write to file', + epilog = '') + +parser.add_argument('filename') # positional argument +parser.add_argument('-o', '--output') # option that takes a value +parser.add_argument('-v', '--verbose', action='store_true') # on/off flag + +args = parser.parse_args() +print(args.filename, args.output, args.verbose) + +def distance(x1,y1,x2,y2): + dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2) + return dist + + +print("Loading Templates") +template_panellum=None +with open("template_panellum.txt",'r') as rf: + template_panellum=rf.readlines() + +template_scenes=None +with open("template_scenes.txt",'r') as rf: + template_scenes=rf.readlines() + +template_hotspots=None +with open("template_hotspots.txt",'r') as rf: + template_hotspots=rf.readlines() + + +linesinput=None +with open(args.filename,'r') as rf: + linesinput=rf.readlines() + +linesinput=[x.rstrip() for x in linesinput] #remove newline and whitespaces at end + +output_scenes=[] + +first_sceneId=None + +for iline1,line1 in enumerate(linesinput): + + x1,y1,z1,id1,filename1,angleoffset1=line1.split(',') + x1,y1,z1=(float(x1),float(y1),float(z1)) + angleoffset1=float(angleoffset1) + + if first_sceneId is None: + first_sceneId=id1 #take first entry as start scene + + # ### Set information for scene ### + current_scene=template_scenes + current_scene=[x.replace('',id1) for x in current_scene] + current_scene=[x.replace('',id1) for x in current_scene] + current_scene=[x.replace('<filename>',filename1) for x in current_scene] + + output_hotspots=[] + + for iline2,line2 in enumerate(linesinput): + x2,y2,z2,id2,filename2,angleoffset2=line2.split(',') + x2,y2,z2=(float(x2),float(y2),float(z2)) + angleoffset2=float(angleoffset2) + + + + if id1!=id2: + print() + print("from "+str(x1)+", "+str(y1)+" : "+id1) + print("to "+str(x2)+", "+str(y2)+" : "+id2) + + print("dist="+str(distance(x1,y1,x2,y2))) + angle=math.degrees(math.atan2(y2-y1, x2-x1)) #in degrees + print("angle="+str(angle)+" offset1="+str(angleoffset1)+" offset2="+str(angleoffset2)) + angle+=angleoffset1 #correct hotspot position by rotation of scene image + print("angle final="+str(angle)) + + pitch=-math.degrees(math.atan(z1/distance(x1,y1,x2,y2))) #from current looking to hotspot. 0deg=straight, 90deg=down + pitch=pitch/2 #manual correction + + + # ### Set information for target/hotspot ### + current_hotspot=template_hotspots + current_hotspot=[x.replace('<id>',id2) for x in current_hotspot] + current_hotspot=[x.replace('<yaw>',str(angle)) for x in current_hotspot] + current_hotspot=[x.replace('<pitch>',str(pitch)) for x in current_hotspot] + + output_hotspots.append(current_hotspot) + + + output_hotspots_string="" + for _ihotspot,_hotspot in enumerate(output_hotspots): + if _ihotspot>0: + output_hotspots_string+=",\n" #separate blocks with comma + for _hotspotline in _hotspot: + output_hotspots_string+=_hotspotline + + current_scene=[x.replace('<hotspot>',output_hotspots_string) for x in current_scene] + + output_scenes.append(current_scene) + + + + +output_scenes_string="" +for _iscene,_scene in enumerate(output_scenes): + if _iscene>0: + output_scenes_string+=",\n" #separate blocks with comma + for _sceneline in _scene: + output_scenes_string+=_sceneline + +output=template_panellum +output=[x.replace('<firstScene>',first_sceneId) for x in output] +output=[x.replace('<scene>',output_scenes_string) for x in output] + +with open(args.output, 'w') as wf: + wf.writelines(output) diff --git a/template_hotspots.txt b/template_hotspots.txt new file mode 100644 index 0000000..8a16c7e --- /dev/null +++ b/template_hotspots.txt @@ -0,0 +1,9 @@ + { + "pitch": <pitch>, + "yaw": <yaw>, + "type": "scene", + "text": "<id>", + "sceneId": "<id>", + "targetYaw": 0, + "targetPitch": 0 + } \ No newline at end of file diff --git a/template_panellum.txt b/template_panellum.txt new file mode 100644 index 0000000..dd1e862 --- /dev/null +++ b/template_panellum.txt @@ -0,0 +1,38 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Tour + + + + + + +
+ + + + + diff --git a/template_scenes.txt b/template_scenes.txt new file mode 100644 index 0000000..201270e --- /dev/null +++ b/template_scenes.txt @@ -0,0 +1,11 @@ + "": { + "title": "", + "hfov": 150, + "pitch": 0, + "yaw": 0, + "type": "equirectangular", + "panorama": "images/<filename>", + "hotSpots": [ +<hotspot> + ] + } \ No newline at end of file