#!/usr/bin/python3 # -*- coding: utf-8 -*- # -*- mode: Python -*- ''' fromGML v0.1.0 Display a GML file See GML specs at the end. Support the gml spec="1.0 (minimum)" and header/client/name and maybe one day drawing/brush/color Licensed under GNU GPLv3 by cocoa and Sam Neurohack Heavy use of : https://github.com/kgn/pygml ''' from __future__ import print_function import time import struct import argparse import sys import xml.etree.ElementTree as etree #import urllib from datetime import datetime import math, random import ast name="generator::fromgml" def debug(*args, **kwargs): if( verbose == False ): return print(*args, file=sys.stderr, **kwargs) argsparser = argparse.ArgumentParser(description="GML file frame generator") argsparser.add_argument("-f","--fps",help="Frame Per Second",default=30,type=int) argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose output") argsparser.add_argument("-g","--gml",help=".gml file",default="147.gml",type=str) argsparser.add_argument("-t","--total",help="Total time",default=32,type=int) argsparser.add_argument("-m","--mode",help="once or anim mode",default="anim",type=str) argsparser.add_argument("-s","--skip",help="% of points to skip",default="0.4",type=float) argsparser.add_argument("-r","--rot",help="(angleX, angleY, angleZ) in degree",default="(0,0,270)",type=str) args = argsparser.parse_args() fps=args.fps verbose=args.verbose mode = args.mode optimal_looptime = 1 / fps angles = ast.literal_eval(args.rot) debug(name+" optimal frame time "+str(optimal_looptime)) TOTAL_TIME=float(args.total) TIME_STRETCH = 1 ZOOM=1.0 DELTA = 7 width = 500 height = 500 centerX = width / 2 centerY = height / 2 # 3D to 2D projection parameters fov = 200 viewer_distance = 2.2 skip = args.skip #skip is the percentage of points that we ignore in order to render # faster in the laser display. Unfortunately we are not able to render too # complex content in our display without resulting in a lot of blinking. # return a list with all points def readGML(filename): outputData = [] tree = etree.parse(filename) root = tree.getroot() ''' if (root.tag.lower() != "gml"): print("Not a GML file.") return ''' #~ tag = root.find("tag") header = tag.find("header") if header != None: client = header.find("client") if client != None: debug("Graffiti name :", client.find("name").text) drawing = tag.find("drawing") environment = header.find("environment") if not environment: environment = tag.find("environment") #screenBounds = environment.find("screenBounds") #globalScale = (1.0,1.0,1.0) #dim = (float(screenBounds.find("x").text) * globalScale[0], float(screenBounds.find("y").text) * globalScale[1], float(screenBounds.find("z").text) * globalScale[2]) #dim = (40.0,40.0,40.0) #~ strokes = drawing.findall("stroke") for stroke in strokes: pointsEl = stroke.findall("pt") for pointEl in pointsEl: x = float(pointEl.find("x").text) - 0.5 y = float(pointEl.find("y").text) - 0.5 z = float(pointEl.find("z").text) - 0.5 transpoint = Rot(x,y,z,angles[0],angles[1],angles[2]) x = (transpoint[0]*ZOOM*width/2) + (width/2) y = (transpoint[1]*ZOOM*height/2) + (height/2) z = transpoint[2] # WIDTH/2 + ZOOM*point[0]*WIDTH/2, HEIGHT/2 + ZOOM*point[1]*HEIGHT/2 time = float(pointEl.find("time").text) outputData.append([x,y,z,time]) #print(outputData) return outputData def Rot(x, y, z, angleX, angleY, angleZ): rad = angleX * math.pi / 180 cosa = math.cos(rad) sina = math.sin(rad) y2 = y y = y2 * cosa - z * sina z = y2 * sina + z * cosa rad = angleY * math.pi / 180 cosa = math.cos(rad) sina = math.sin(rad) z2 = z z = z2 * cosa - x * sina x = z2 * sina + x * cosa rad = angleZ * math.pi / 180 cosa = math.cos(rad) sina = math.sin(rad) x2 = x x = x2 * cosa - y * sina y = x2 * sina + y * cosa return (x,y,z) #[x,y,z,time] def iterPoints(): for point in gml: yield point # Play once during total time arg def Once(): debug(name,"play once mode") shape = [] for point in gml: shape.append([point[0],point[1], 65535]) debug(name + str(shape)) t0=datetime.now() deltat=0 while deltat TOTAL_TIME: t0=datetime.now() first=True shape = [] for point in iterPoints(): if point[3] <= deltat and deltat <= point[3]+DELTA and random.random()<(1-skip): if first: first=False else: #LD.draw_point(WIDTH/2 + ZOOM*point.x*WIDTH/2, HEIGHT/2 + ZOOM*point.y*HEIGHT/2) shape.append([point[0], point[1], 65535]) print(shape, flush=True); debug(name + " Reading : "+args.gml+" in "+mode+" mode.") gml = readGML(args.gml) debug(name + " total points : "+ str(len(gml))) if mode =="once": Once() else: Anim() debug(name + " ends.") exit() ''' 0.0 0.0
Laser Tag 2.0 MyUserName http://000000book.com/data/156/ katsu,paris,2010 28sks922ks992 192.168.1.1 -39.392922 53.29292 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1.0 0.0 1024 768 0 0 0 0 1000 600 0 cm yourimage.jpg
0.0 0.0 0.0 0.013 0 LaserTagArrowLetters http://aurltodescribethebrushspec.com/someSpec.xml 10 1.5 1.0 1.0 0 255 255 255 255 0 1 0 0.0 0.0 0.0 0.013 0.0 0.0 0.0 0.023 true 255 255 0 -1 0.0 0.0 0.0 0.0 0.5 0.5
'''