mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-26 08:56:36 +00:00
Final ENNTool commit.
This commit is contained in:
parent
4817313bbc
commit
52ffd7f4c4
0
.gitignore → ENNTool/.gitignore
vendored
0
.gitignore → ENNTool/.gitignore
vendored
@ -5,13 +5,20 @@
|
|||||||
# This project is licensed under the terms of the MIT license.
|
# This project is licensed under the terms of the MIT license.
|
||||||
#
|
#
|
||||||
# TODO:
|
# TODO:
|
||||||
# 1) -A: render frame #1, render frame #2, ...
|
# 1) -A, -S: replace w/ -s, implement animation script: render frame #1, render frame #2, ...; scrolling script; effects: rotate, smash into bricks, swirl, wave, ...
|
||||||
# 2) -s: effects: rotate, smash into bricks, swirl, wave, ...
|
# 2) Feature: include ETA(s) @ progress bar(s)
|
||||||
# 3) Feature: include ETA @ progress bar
|
# 3) Feature: autodetect video width from widest mircart
|
||||||
# 4) Feature: autodetect video width from widest mircart
|
# 4) Feature: render mircart as 3D blocks vs flat surface
|
||||||
# 5) Feature: render mircart as 3D blocks vs flat surface
|
|
||||||
# 6) OpenGL: use VAOs + glVertexAttribFormat + glVertexAttribBinding
|
#
|
||||||
# 7) use names @ optdict[] + set from optdefaults
|
# 1) Optimisation: speed up ENNToolMiRCARTImporter
|
||||||
|
# 2) Cleanup: use names @ optdict + set from optdefaults
|
||||||
|
# 3) Feature: scrolling speed as <how many Y units>x<count of frame(s)>
|
||||||
|
# 4) Cleanup: use VAOs + glVertexAttribFormat + glVertexAttribBinding
|
||||||
|
# 5) Optimisation: split mIRC art into separate VBOs & implement rudimentary culling
|
||||||
|
# 6) Optimisation: only call glReadPixels() when changes were made relative to the last call
|
||||||
|
# 7) Split video output into separate module, switch to GUI
|
||||||
|
# 8) FBOs http://www.songho.ca/opengl/gl_fbo.html
|
||||||
#
|
#
|
||||||
|
|
||||||
from getopt import getopt, GetoptError
|
from getopt import getopt, GetoptError
|
||||||
@ -20,7 +27,7 @@ from OpenGL.GL import *
|
|||||||
import os, sys, time
|
import os, sys, time
|
||||||
import wx
|
import wx
|
||||||
|
|
||||||
from ENNToolGLCanvasPanel import ENNToolGLCanvasPanel
|
from ENNToolGLCanvasPanel import ENNToolGLCanvas, ENNToolGLPanel
|
||||||
from ENNToolGLTTFTexture import ENNToolGLTTFTexture
|
from ENNToolGLTTFTexture import ENNToolGLTTFTexture
|
||||||
from ENNToolGLVideoWriter import ENNToolGLVideoWriter
|
from ENNToolGLVideoWriter import ENNToolGLVideoWriter
|
||||||
from ENNToolMiRCARTImporter import ENNToolMiRCARTImporter
|
from ENNToolMiRCARTImporter import ENNToolMiRCARTImporter
|
||||||
@ -52,8 +59,6 @@ class ENNToolApp(object):
|
|||||||
|
|
||||||
if "-h" in optdict:
|
if "-h" in optdict:
|
||||||
usage(sys.argv[0]); exit(0);
|
usage(sys.argv[0]); exit(0);
|
||||||
elif not "-o" in optdict:
|
|
||||||
raise GetoptError("-o fname must be specified")
|
|
||||||
elif not len(argv):
|
elif not len(argv):
|
||||||
raise GetoptError("at least one MiRCART input fname must be specified")
|
raise GetoptError("at least one MiRCART input fname must be specified")
|
||||||
|
|
||||||
@ -82,8 +87,8 @@ class ENNToolApp(object):
|
|||||||
print("\r[{:<50}] {}%".format(
|
print("\r[{:<50}] {}%".format(
|
||||||
("=" * int(progressDiv * 50)), int(progressDiv * 100)), end=endChar)
|
("=" * int(progressDiv * 50)), int(progressDiv * 100)), end=endChar)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ modeScroll(self, argv, optdict, GLVideoWriter, panelGLCanvas, fps=25, scrollRate=0.25): XXX
|
# {{{ modeScroll(self, argv, optdict, GLVideoWriter, GLpanel, GLpanel, fps=25, scrollRate=0.1): XXX
|
||||||
def modeScroll(self, argv, optdict, GLVideoWriter, panelGLCanvas, fps=25, scrollRate=0.25):
|
def modeScroll(self, argv, optdict, GLVideoWriter, GLcanvas, GLpanel, fps=25, scrollRate=0.1):
|
||||||
MiRCART = []
|
MiRCART = []
|
||||||
if "-v" in optdict:
|
if "-v" in optdict:
|
||||||
time0 = time.time()
|
time0 = time.time()
|
||||||
@ -93,53 +98,74 @@ class ENNToolApp(object):
|
|||||||
if "-v" in optdict:
|
if "-v" in optdict:
|
||||||
print("mIRC art import delta {:.3f}ms".format((time.time() - time0) * 1000))
|
print("mIRC art import delta {:.3f}ms".format((time.time() - time0) * 1000))
|
||||||
|
|
||||||
curY, rotateX, rotateY, translateY = 0, 0, 0, scrollRate
|
|
||||||
if "-v" in optdict:
|
if "-v" in optdict:
|
||||||
time0 = time.time()
|
time0 = time.time()
|
||||||
artTextureId, artInfo = ENNToolGLTTFTexture(MiRCART, optdict["-R"], optdict["-r"]).getParams()
|
artTextureId, artInfo = ENNToolGLTTFTexture(MiRCART, optdict["-R"], optdict["-r"]).getParams()
|
||||||
if "-v" in optdict:
|
if "-v" in optdict:
|
||||||
print("TTF texture generation delta {:.3f}ms".format((time.time() - time0) * 1000))
|
print("TTF texture generation delta {:.3f}ms".format((time.time() - time0) * 1000))
|
||||||
artVbo, artVboLen, lastY, numVertices = panelGLCanvas.renderMiRCART(artInfo, MiRCART, cubeSize=optdict["-R"])
|
artVbo, artVboLen, lastY, numVertices = GLcanvas.renderMiRCART(artInfo, MiRCART, cubeSize=optdict["-R"])
|
||||||
if "-v" in optdict:
|
if "-v" in optdict:
|
||||||
print("{} vertices".format(numVertices))
|
print("{} vertices".format(numVertices))
|
||||||
w, h = panelGLCanvas.GetClientSize(); w, h = max(w, 1.0), max(h, 1.0);
|
def scrollFrameFun():
|
||||||
|
curY, rotateX, rotateY, translateY = 0, 0, 0, scrollRate
|
||||||
while True:
|
w, h = GLcanvas.GetClientSize(); w, h = max(w, 1.0), max(h, 1.0);
|
||||||
|
def scrollFrame():
|
||||||
|
nonlocal curY
|
||||||
self.printProgress(curY, lastY)
|
self.printProgress(curY, lastY)
|
||||||
for numFrame in range(fps):
|
GLcanvas.renderFrame(artTextureId, artVbo, artVboLen)
|
||||||
panelGLCanvas.renderFrame(artTextureId, artVbo, artVboLen)
|
|
||||||
if translateY:
|
if translateY:
|
||||||
glTranslatef(0, translateY, 0); curY += translateY
|
glTranslatef(0, translateY, 0); curY += translateY
|
||||||
if rotateX:
|
if rotateX:
|
||||||
glRotatef(rotateX * (180.0/w), 0.0, 1.0, 0.0)
|
glRotatef(rotateX * (180.0/w), 0.0, 1.0, 0.0)
|
||||||
if rotateY:
|
if rotateY:
|
||||||
glRotatef(rotateY * (180.0/h), 1.0, 0.0, 0.0)
|
glRotatef(rotateY * (180.0/h), 1.0, 0.0, 0.0)
|
||||||
|
if "-o" in optdict:
|
||||||
GLVideoWriter.saveFrame()
|
GLVideoWriter.saveFrame()
|
||||||
|
else:
|
||||||
|
GLcanvas.SwapBuffers()
|
||||||
if curY >= lastY:
|
if curY >= lastY:
|
||||||
self.printProgress(curY, lastY); break;
|
self.printProgress(curY, lastY)
|
||||||
|
if "-o" in optdict:
|
||||||
GLVideoWriter.saveVideo()
|
GLVideoWriter.saveVideo()
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
return scrollFrame
|
||||||
|
if "-o" in optdict:
|
||||||
|
frameFun = scrollFrameFun()
|
||||||
|
while True:
|
||||||
|
if not frameFun():
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
GLpanel.frameFun = scrollFrameFun()
|
||||||
|
self.wxApp.MainLoop()
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ __init__(self, argv): XXX
|
# {{{ __init__(self, argv): XXX
|
||||||
def __init__(self, argv):
|
def __init__(self, argv):
|
||||||
argv, optdict = self.parseArgv(argv)
|
argv, optdict = self.parseArgv(argv)
|
||||||
wxApp = wx.App(False)
|
self.wxApp = wx.App(False)
|
||||||
appFrameSize = optdict["-r"]
|
appFrameSize = [c + 128 for c in optdict["-r"]]
|
||||||
appFrame = wx.Frame(None, size=appFrameSize); appFrame.Hide();
|
self.appFrame = wx.Frame(None, size=appFrameSize)
|
||||||
appPanelSkin = wx.Panel(appFrame, wx.ID_ANY)
|
appPanelSkin = wx.Panel(self.appFrame, wx.ID_ANY)
|
||||||
|
|
||||||
videoFps, videoPath = int(optdict["-f"]), optdict["-o"]
|
videoFps, videoPath = int(optdict["-f"]), optdict["-o"] if "-o" in optdict else None
|
||||||
panelGLCanvas = ENNToolGLCanvasPanel(appPanelSkin, size=appFrameSize)
|
GLpanel = ENNToolGLPanel(appPanelSkin, size=optdict["-r"], parentFrame=self.appFrame)
|
||||||
panelGLCanvas.initOpenGL()
|
GLcanvas = ENNToolGLCanvas(GLpanel, optdict["-r"])
|
||||||
panelGLCanvas.initShaders()
|
GLcanvas.initOpenGL()
|
||||||
GLVideoWriter = ENNToolGLVideoWriter(videoPath, panelGLCanvas.GetClientSize(), videoFps=videoFps)
|
GLcanvas.initShaders()
|
||||||
|
GLVideoWriter = ENNToolGLVideoWriter(videoPath, GLpanel.GetClientSize(), videoFps=videoFps)
|
||||||
|
|
||||||
|
if "-o" in optdict:
|
||||||
|
self.appFrame.Hide()
|
||||||
|
else:
|
||||||
|
self.appFrame.Show(); self.appFrame.SetFocus();
|
||||||
|
|
||||||
if "-v" in optdict:
|
if "-v" in optdict:
|
||||||
time0 = time.time()
|
time0 = time.time()
|
||||||
self.modeScroll(argv, optdict, GLVideoWriter, panelGLCanvas, fps=videoFps)
|
self.modeScroll(argv, optdict, GLVideoWriter, GLcanvas, GLpanel, fps=videoFps)
|
||||||
if "-v" in optdict:
|
if "-v" in optdict:
|
||||||
print("delta {}s".format(time.time() - time0))
|
print("delta {}s".format(time.time() - time0))
|
||||||
if "-p" in optdict:
|
if "-o" in optdict \
|
||||||
|
and "-p" in optdict:
|
||||||
os.startfile(videoPath)
|
os.startfile(videoPath)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
@ -14,13 +14,12 @@
|
|||||||
# Tue, 03 Jul 2018 14:34:57 +0200 [7] <https://gamedev.stackexchange.com/questions/107793/binding-and-unbinding-what-would-you-do>
|
# Tue, 03 Jul 2018 14:34:57 +0200 [7] <https://gamedev.stackexchange.com/questions/107793/binding-and-unbinding-what-would-you-do>
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from ENNToolMiRCARTColours import ENNToolMiRCARTColoursFloat
|
||||||
from OpenGL.GL import *
|
from OpenGL.GL import *
|
||||||
from OpenGL.GL import shaders
|
from OpenGL.GL import shaders
|
||||||
import ctypes, wx, wx.glcanvas
|
import ctypes, wx, wx.glcanvas
|
||||||
|
|
||||||
class ENNToolGLCanvasPanel(wx.glcanvas.GLCanvas, wx.Panel):
|
class ENNToolGLCanvas(wx.glcanvas.GLCanvas):
|
||||||
"""XXX"""
|
|
||||||
|
|
||||||
# {{{ initOpenGL(self): XXX
|
# {{{ initOpenGL(self): XXX
|
||||||
def initOpenGL(self):
|
def initOpenGL(self):
|
||||||
self.glContext = wx.glcanvas.GLContext(self)
|
self.glContext = wx.glcanvas.GLContext(self)
|
||||||
@ -32,7 +31,6 @@ class ENNToolGLCanvasPanel(wx.glcanvas.GLCanvas, wx.Panel):
|
|||||||
glLoadIdentity(); glFrustum(-1, 1, -1, 1, 1, 100);
|
glLoadIdentity(); glFrustum(-1, 1, -1, 1, 1, 100);
|
||||||
glMatrixMode(GL_MODELVIEW)
|
glMatrixMode(GL_MODELVIEW)
|
||||||
glEnable(GL_DEPTH_TEST)
|
glEnable(GL_DEPTH_TEST)
|
||||||
glClearColor(0, 0, 0, 1); glClearDepth(1);
|
|
||||||
glTranslatef(-5.0, 3.0, -5)
|
glTranslatef(-5.0, 3.0, -5)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ initShaders(self): XXX
|
# {{{ initShaders(self): XXX
|
||||||
@ -41,12 +39,20 @@ class ENNToolGLCanvasPanel(wx.glcanvas.GLCanvas, wx.Panel):
|
|||||||
fs = shaders.compileShader("""
|
fs = shaders.compileShader("""
|
||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
in vec2 fgTexCoord;
|
in vec2 frgTexCoord;
|
||||||
|
in vec3 frgFgColour;
|
||||||
|
in vec3 frgBgColour;
|
||||||
uniform sampler2D texture;
|
uniform sampler2D texture;
|
||||||
|
|
||||||
|
layout(location = 0) out vec4 fragColour;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 texel = texture2D(texture, fgTexCoord);
|
vec4 texel = texture2D(texture, frgTexCoord);
|
||||||
gl_FragColor = vec4(texel.r, texel.g, texel.b, 1.0);
|
if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0 && texel.a == 0.0) {
|
||||||
|
fragColour = vec4(frgBgColour.r, frgBgColour.g, frgBgColour.b, 1.0);
|
||||||
|
} else {
|
||||||
|
fragColour = vec4(frgFgColour.r, frgFgColour.g, frgFgColour.b, 1.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
""", GL_FRAGMENT_SHADER)
|
""", GL_FRAGMENT_SHADER)
|
||||||
|
|
||||||
@ -56,15 +62,21 @@ class ENNToolGLCanvasPanel(wx.glcanvas.GLCanvas, wx.Panel):
|
|||||||
|
|
||||||
layout(location = 0) in vec4 vertex;
|
layout(location = 0) in vec4 vertex;
|
||||||
layout(location = 1) in vec2 texcoord;
|
layout(location = 1) in vec2 texcoord;
|
||||||
|
layout(location = 2) in vec3 vexFgColour;
|
||||||
|
layout(location = 3) in vec3 vexBgColour;
|
||||||
|
|
||||||
out vec2 fgTexCoord;
|
out vec2 frgTexCoord;
|
||||||
|
out vec3 frgFgColour;
|
||||||
|
out vec3 frgBgColour;
|
||||||
|
|
||||||
uniform mat4 modelview;
|
uniform mat4 modelview;
|
||||||
uniform mat4 projection;
|
uniform mat4 projection;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = projection * modelview * vertex;
|
gl_Position = projection * modelview * vertex;
|
||||||
fgTexCoord = texcoord;
|
frgTexCoord = texcoord;
|
||||||
|
frgFgColour = vexFgColour;
|
||||||
|
frgBgColour = vexBgColour;
|
||||||
}
|
}
|
||||||
""", GL_VERTEX_SHADER)
|
""", GL_VERTEX_SHADER)
|
||||||
self.shader = shaders.compileProgram(vs, fs)
|
self.shader = shaders.compileProgram(vs, fs)
|
||||||
@ -86,13 +98,23 @@ class ENNToolGLCanvasPanel(wx.glcanvas.GLCanvas, wx.Panel):
|
|||||||
|
|
||||||
# VBO vertices location
|
# VBO vertices location
|
||||||
glEnableVertexAttribArray(0)
|
glEnableVertexAttribArray(0)
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, False, 20, ctypes.c_void_p(0))
|
glVertexAttribPointer(0, 3, GL_FLOAT, False, 44, ctypes.c_void_p(0))
|
||||||
glVertexPointer(3, GL_FLOAT, 20, ctypes.c_void_p(0))
|
glVertexPointer(3, GL_FLOAT, 44, ctypes.c_void_p(0))
|
||||||
|
|
||||||
# VBO texture coordinates
|
# VBO texture coordinates
|
||||||
glEnableVertexAttribArray(1)
|
glEnableVertexAttribArray(1)
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, False, 20, ctypes.c_void_p(12))
|
glVertexAttribPointer(1, 2, GL_FLOAT, False, 44, ctypes.c_void_p(12))
|
||||||
glTexCoordPointer(2, GL_FLOAT, 20, ctypes.c_void_p(12))
|
glTexCoordPointer(2, GL_FLOAT, 44, ctypes.c_void_p(12))
|
||||||
|
|
||||||
|
# VBO foreground colours
|
||||||
|
glEnableVertexAttribArray(2)
|
||||||
|
glVertexAttribPointer(2, 3, GL_FLOAT, False, 44, ctypes.c_void_p(20))
|
||||||
|
glTexCoordPointer(3, GL_FLOAT, 44, ctypes.c_void_p(20))
|
||||||
|
|
||||||
|
# VBO background colours
|
||||||
|
glEnableVertexAttribArray(3)
|
||||||
|
glVertexAttribPointer(3, 3, GL_FLOAT, False, 44, ctypes.c_void_p(32))
|
||||||
|
glTexCoordPointer(3, GL_FLOAT, 44, ctypes.c_void_p(32))
|
||||||
|
|
||||||
# Clear colour and depth buffer, draw quads from VBO & clear state
|
# Clear colour and depth buffer, draw quads from VBO & clear state
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
||||||
@ -111,19 +133,27 @@ class ENNToolGLCanvasPanel(wx.glcanvas.GLCanvas, wx.Panel):
|
|||||||
cubeBg = artMap[numRow][numCol][1]
|
cubeBg = artMap[numRow][numCol][1]
|
||||||
cubeAttrs = artMap[numRow][numCol][2]
|
cubeAttrs = artMap[numRow][numCol][2]
|
||||||
cubeChar = artMap[numRow][numCol][3]
|
cubeChar = artMap[numRow][numCol][3]
|
||||||
artCell = artInfo[cubeFg][cubeBg][cubeAttrs][cubeChar]
|
artCell = artInfo[cubeAttrs][cubeChar]
|
||||||
|
|
||||||
# Top Right, Top Left
|
# Top Right, Top Left
|
||||||
vertices += curPos
|
vertices += curPos
|
||||||
vertices += artCell[0:2]
|
vertices += artCell[0:2]
|
||||||
|
vertices += [*ENNToolMiRCARTColoursFloat[cubeFg]]
|
||||||
|
vertices += [*ENNToolMiRCARTColoursFloat[cubeBg]]
|
||||||
vertices += [curPos[0] - cubeSize[0], curPos[1], curPos[2]]
|
vertices += [curPos[0] - cubeSize[0], curPos[1], curPos[2]]
|
||||||
vertices += artCell[2:4]
|
vertices += artCell[2:4]
|
||||||
|
vertices += ENNToolMiRCARTColoursFloat[cubeFg]
|
||||||
|
vertices += ENNToolMiRCARTColoursFloat[cubeBg]
|
||||||
|
|
||||||
# Bottom Left, Bottom Right
|
# Bottom Left, Bottom Right
|
||||||
vertices += [curPos[0] - cubeSize[0], curPos[1] - cubeSize[1], curPos[2]]
|
vertices += [curPos[0] - cubeSize[0], curPos[1] - cubeSize[1], curPos[2]]
|
||||||
vertices += artCell[4:6]
|
vertices += artCell[4:6]
|
||||||
|
vertices += [*ENNToolMiRCARTColoursFloat[cubeFg]]
|
||||||
|
vertices += [*ENNToolMiRCARTColoursFloat[cubeBg]]
|
||||||
vertices += [curPos[0], curPos[1] - cubeSize[1], curPos[2]]
|
vertices += [curPos[0], curPos[1] - cubeSize[1], curPos[2]]
|
||||||
vertices += artCell[6:8]
|
vertices += artCell[6:8]
|
||||||
|
vertices += ENNToolMiRCARTColoursFloat[cubeFg]
|
||||||
|
vertices += ENNToolMiRCARTColoursFloat[cubeBg]
|
||||||
|
|
||||||
curPos[0], numVertices = curPos[0] + cubeSize[0], numVertices + 4
|
curPos[0], numVertices = curPos[0] + cubeSize[0], numVertices + 4
|
||||||
curPos[0], curPos[1] = 0, curPos[1] - cubeSize[1]
|
curPos[0], curPos[1] = 0, curPos[1] - cubeSize[1]
|
||||||
@ -135,10 +165,40 @@ class ENNToolGLCanvasPanel(wx.glcanvas.GLCanvas, wx.Panel):
|
|||||||
GL_STATIC_DRAW)
|
GL_STATIC_DRAW)
|
||||||
return artVbo, len(vertices), -curPos[1], numVertices
|
return artVbo, len(vertices), -curPos[1], numVertices
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ __init__(self, parent, size, defaultPos=(24,24)): initialisation method
|
# {{{ __init__(self, parentCanvas, size): initialisation method
|
||||||
def __init__(self, parent, size, defaultPos=(24,24)):
|
def __init__(self, parentCanvas, size):
|
||||||
|
super().__init__(parentCanvas, size=size)
|
||||||
|
self.curSize = list(size)
|
||||||
|
self.parentCanvas = parentCanvas
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
class ENNToolGLPanel(wx.Panel):
|
||||||
|
"""XXX"""
|
||||||
|
|
||||||
|
# {{{ onPaint(self, event): XXX
|
||||||
|
def onPaint(self, event):
|
||||||
|
eventDc = wx.PaintDC(self)
|
||||||
|
eventUpdates = wx.RegionIterator(self.GetUpdateRegion())
|
||||||
|
paintFlag = True if eventUpdates.HaveRects() else False
|
||||||
|
if self.frameFun != None:
|
||||||
|
self.frameFun()
|
||||||
|
# }}}
|
||||||
|
# {{{ onTimer(self, event): XXX
|
||||||
|
def onTimer(self, event):
|
||||||
|
if self.frameFun != None:
|
||||||
|
if not self.frameFun():
|
||||||
|
event.GetTimer().Stop()
|
||||||
|
event.GetTimer().Destroy()
|
||||||
|
# }}}
|
||||||
|
# {{{ __init__(self, parent, size, defaultPos=(24,24), parentFrame=None): initialisation method
|
||||||
|
def __init__(self, parent, size, defaultPos=(24,24), parentFrame=None):
|
||||||
super().__init__(parent, pos=defaultPos, size=size)
|
super().__init__(parent, pos=defaultPos, size=size)
|
||||||
self.curPos = list(defaultPos); self.curSize = list(size);
|
self.curPos = list(defaultPos); self.curSize = list(size);
|
||||||
|
self.Bind(wx.EVT_PAINT, self.onPaint)
|
||||||
|
self.frameFun = None
|
||||||
|
self.timerTimer = wx.Timer(self, 1)
|
||||||
|
self.timerTimer.Start(40)
|
||||||
|
self.Bind(wx.EVT_TIMER, self.onTimer, self.timerTimer)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
@ -10,6 +10,7 @@
|
|||||||
# Wed, 27 Jun 2018 16:02:12 +0200 [3] <https://www.khronos.org/opengl/wiki/How_lighting_works#Good_Settings.>
|
# Wed, 27 Jun 2018 16:02:12 +0200 [3] <https://www.khronos.org/opengl/wiki/How_lighting_works#Good_Settings.>
|
||||||
# Wed, 27 Jun 2018 16:02:13 +0200 [4] <https://www.khronos.org/opengl/wiki/Common_Mistakes>
|
# Wed, 27 Jun 2018 16:02:13 +0200 [4] <https://www.khronos.org/opengl/wiki/Common_Mistakes>
|
||||||
# Wed, 27 Jun 2018 16:02:14 +0200 [5] <https://www.khronos.org/opengl/wiki/Pixel_Transfer#Pixel_layout>
|
# Wed, 27 Jun 2018 16:02:14 +0200 [5] <https://www.khronos.org/opengl/wiki/Pixel_Transfer#Pixel_layout>
|
||||||
|
# Wed, 04 Jul 2018 10:57:09 +0200 [6] <https://stackoverflow.com/questions/466204/rounding-up-to-next-power-of-2>
|
||||||
#
|
#
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
@ -33,33 +34,38 @@ class ENNToolGLTTFTexture(object):
|
|||||||
def _nestedDict():
|
def _nestedDict():
|
||||||
return defaultdict(ENNToolGLTTFTexture._nestedDict)
|
return defaultdict(ENNToolGLTTFTexture._nestedDict)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ _drawCharList(self, artInfo, charList, pilFontBold, pilFontNormal, pilFontSize, pilImageDraw, pilImageSize): XXX
|
# {{{ _drawCharList(self, artInfo, charList, pilFontBold, pilFontNormal, pilImageDraw, pilImageSize): XXX
|
||||||
def _drawCharList(self, artInfo, charList, pilFontBold, pilFontNormal, pilFontSize, pilImageDraw, pilImageSize):
|
def _drawCharList(self, artInfo, charList, pilFontBold, pilFontNormal, pilImageDraw, pilImageSize):
|
||||||
curPos = [0, 0]
|
curPos = [0, 0]
|
||||||
for newChar in charList:
|
for newChar in charList:
|
||||||
pilFont, underLine = pilFontNormal, False
|
|
||||||
if newChar[2] & ENNToolMiRCARTImporter._CellState.CS_BOLD:
|
if newChar[2] & ENNToolMiRCARTImporter._CellState.CS_BOLD:
|
||||||
pilFont = pilFontBold
|
pilFont, pilFontSize = pilFontBold, [pilFontBold.getsize(newChar[3])[0], pilFontBold.getsize(newChar[3])[1]]
|
||||||
|
else:
|
||||||
|
pilFont, pilFontSize = pilFontNormal, [pilFontNormal.getsize(newChar[3])[0], pilFontNormal.getsize(newChar[3])[1]]
|
||||||
if newChar[2] & ENNToolMiRCARTImporter._CellState.CS_UNDERLINE:
|
if newChar[2] & ENNToolMiRCARTImporter._CellState.CS_UNDERLINE:
|
||||||
underLine = True
|
underLine = True
|
||||||
|
else:
|
||||||
|
underLine = False
|
||||||
|
if newChar[3] != " ":
|
||||||
|
pilImageDraw.text(curPos, newChar[3], (255, 255, 255, 255), pilFont)
|
||||||
|
elif newChar[0] == newChar[1]:
|
||||||
pilImageDraw.rectangle((*curPos, curPos[0] + pilFontSize[0], curPos[1] + pilFontSize[1] - 1),
|
pilImageDraw.rectangle((*curPos, curPos[0] + pilFontSize[0], curPos[1] + pilFontSize[1] - 1),
|
||||||
fill=(*ENNToolMiRCARTColours[newChar[1]], 255))
|
fill=(255, 255, 255, 255))
|
||||||
pilImageDraw.text(curPos, newChar[3], (*ENNToolMiRCARTColours[newChar[0]], 255), pilFont)
|
if underLine and False:
|
||||||
if underLine:
|
|
||||||
pilImageDraw.line(
|
pilImageDraw.line(
|
||||||
xy=(curPos[0], curPos[1] + (pilFontSize[1] - 2),
|
xy=(curPos[0], curPos[1] + (pilFontSize[1] - 2),
|
||||||
curPos[0] + pilFontSize[0], curPos[1] + pilFontSize[1]),
|
curPos[0] + pilFontSize[0], curPos[1] + pilFontSize[1]),
|
||||||
fill=(*ENNToolMiRCARTColours[newChar[0]], 255))
|
fill=(*ENNToolMiRCARTColours[newChar[0]], 255))
|
||||||
|
|
||||||
artInfo[newChar[0]][newChar[1]][newChar[2]][newChar[3]] = []
|
artInfo[newChar[2]][newChar[3]] = []
|
||||||
# Top Right
|
# Top Right
|
||||||
artInfo[newChar[0]][newChar[1]][newChar[2]][newChar[3]] += [float(curPos[0] + pilFontSize[0]) / pilImageSize[0], 0.0]
|
artInfo[newChar[2]][newChar[3]] += [float(curPos[0] + pilFontSize[0]) / pilImageSize[0], 0.0]
|
||||||
# Top Left
|
# Top Left
|
||||||
artInfo[newChar[0]][newChar[1]][newChar[2]][newChar[3]] += [float(curPos[0]) / pilImageSize[0], 0.0]
|
artInfo[newChar[2]][newChar[3]] += [float(curPos[0]) / pilImageSize[0], 0.0]
|
||||||
# Bottom Left
|
# Bottom Left
|
||||||
artInfo[newChar[0]][newChar[1]][newChar[2]][newChar[3]] += [float(curPos[0]) / pilImageSize[0], float(pilFontSize[1]) / pilImageSize[1]]
|
artInfo[newChar[2]][newChar[3]] += [float(curPos[0]) / pilImageSize[0], float(pilFontSize[1]) / pilImageSize[1]]
|
||||||
# Bottom Right
|
# Bottom Right
|
||||||
artInfo[newChar[0]][newChar[1]][newChar[2]][newChar[3]] += [float(curPos[0] + pilFontSize[0]) / pilImageSize[0], float(pilFontSize[1]) / pilImageSize[1]]
|
artInfo[newChar[2]][newChar[3]] += [float(curPos[0] + pilFontSize[0]) / pilImageSize[0], float(pilFontSize[1]) / pilImageSize[1]]
|
||||||
|
|
||||||
curPos[0] += pilFontSize[0]
|
curPos[0] += pilFontSize[0]
|
||||||
return artInfo
|
return artInfo
|
||||||
@ -73,24 +79,33 @@ class ENNToolGLTTFTexture(object):
|
|||||||
artBg = artMap[numRow][numCol][1]
|
artBg = artMap[numRow][numCol][1]
|
||||||
artAttrs = artMap[numRow][numCol][2]
|
artAttrs = artMap[numRow][numCol][2]
|
||||||
artChar = artMap[numRow][numCol][3]
|
artChar = artMap[numRow][numCol][3]
|
||||||
if artInfo[artFg][artBg][artAttrs][artChar] == {}:
|
if artInfo[artAttrs][artChar] == {}:
|
||||||
artInfo[artFg][artBg][artAttrs][artChar] = None
|
artInfo[artAttrs][artChar] = None
|
||||||
charList += [[artFg, artBg, artAttrs, artChar]]
|
charList += [[artFg, artBg, artAttrs, artChar]]
|
||||||
return artInfo, charList
|
return artInfo, charList
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ _initFonts(self): XXX
|
# {{{ _initFonts(self, charMap): XXX
|
||||||
def _initFonts(self):
|
def _initFonts(self, charMap):
|
||||||
fontBoldPathName = os.path.join("assets", "DejaVuSansMono-Bold.ttf")
|
fontBoldPathName = os.path.join("assets", "DejaVuSansMono-Bold.ttf")
|
||||||
fontNormalPathName = os.path.join("assets", "DejaVuSansMono.ttf")
|
fontNormalPathName = os.path.join("assets", "DejaVuSansMono.ttf")
|
||||||
fontSize = int("26")
|
fontSize = int("26")
|
||||||
pilFontBold = ImageFont.truetype(fontBoldPathName, fontSize)
|
pilFontBold = ImageFont.truetype(fontBoldPathName, fontSize)
|
||||||
|
pilFontMaxSize = [16, 32] # TODO
|
||||||
pilFontNormal = ImageFont.truetype(fontNormalPathName, fontSize)
|
pilFontNormal = ImageFont.truetype(fontNormalPathName, fontSize)
|
||||||
pilFontSize = list(pilFontNormal.getsize("_")) # XXX
|
return pilFontBold, pilFontMaxSize, pilFontNormal
|
||||||
return pilFontBold, pilFontNormal, pilFontSize
|
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ _initImage(self, charList, pilFontSize): XXX
|
# {{{ _initImage(self, charList, pilFontMaxSize): XXX
|
||||||
def _initImage(self, charList, pilFontSize):
|
def _initImage(self, charList, pilFontMaxSize):
|
||||||
pilImageSize = (pilFontSize[0] * len(charList), pilFontSize[1])
|
pilImageSize = [pilFontMaxSize[0] * len(charList), pilFontMaxSize[1]]
|
||||||
|
for numDim in range(len(pilImageSize)):
|
||||||
|
if (pilImageSize[numDim] & (pilImageSize[numDim] - 1)) != 0:
|
||||||
|
pilImageSize[numDim] -= 1
|
||||||
|
pilImageSize[numDim] |= pilImageSize[numDim] >> 1
|
||||||
|
pilImageSize[numDim] |= pilImageSize[numDim] >> 2
|
||||||
|
pilImageSize[numDim] |= pilImageSize[numDim] >> 4
|
||||||
|
pilImageSize[numDim] |= pilImageSize[numDim] >> 8
|
||||||
|
pilImageSize[numDim] |= pilImageSize[numDim] >> 16
|
||||||
|
pilImageSize[numDim] += 1
|
||||||
pilImage = Image.new("RGBA", pilImageSize, (0, 0, 0, 0))
|
pilImage = Image.new("RGBA", pilImageSize, (0, 0, 0, 0))
|
||||||
pilImageDraw = ImageDraw.Draw(pilImage)
|
pilImageDraw = ImageDraw.Draw(pilImage)
|
||||||
return pilImage, pilImageDraw, pilImageSize
|
return pilImage, pilImageDraw, pilImageSize
|
||||||
@ -115,7 +130,6 @@ class ENNToolGLTTFTexture(object):
|
|||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
|
||||||
artTextureImage.size[0], artTextureImage.size[1],
|
artTextureImage.size[0], artTextureImage.size[1],
|
||||||
0, GL_RGBA, GL_UNSIGNED_BYTE, artTextureImageData)
|
0, GL_RGBA, GL_UNSIGNED_BYTE, artTextureImageData)
|
||||||
glGenerateMipmap(GL_TEXTURE_2D)
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0)
|
glBindTexture(GL_TEXTURE_2D, 0)
|
||||||
return artTextureId
|
return artTextureId
|
||||||
@ -127,11 +141,9 @@ class ENNToolGLTTFTexture(object):
|
|||||||
# {{{ __init__(self): initialisation method
|
# {{{ __init__(self): initialisation method
|
||||||
def __init__(self, artMap, cubeSize, videoSize):
|
def __init__(self, artMap, cubeSize, videoSize):
|
||||||
artInfo, charList = self._initArtInfoCharList(artMap)
|
artInfo, charList = self._initArtInfoCharList(artMap)
|
||||||
pilFontBold, pilFontNormal, pilFontSize = self._initFonts()
|
pilFontBold, pilFontMaxSize, pilFontNormal = self._initFonts(charList)
|
||||||
pilImage, pilImageDraw, pilImageSize = self._initImage(charList, pilFontSize)
|
pilImage, pilImageDraw, pilImageSize = self._initImage(charList, pilFontMaxSize)
|
||||||
artInfo = self._drawCharList(artInfo, charList,
|
artInfo = self._drawCharList(artInfo, charList, pilFontBold, pilFontNormal, pilImageDraw, pilImageSize)
|
||||||
pilFontBold, pilFontNormal, pilFontSize,
|
|
||||||
pilImageDraw, pilImageSize)
|
|
||||||
artTextureId = self._initTexture(pilImage)
|
artTextureId = self._initTexture(pilImage)
|
||||||
self.artTextureId = artTextureId
|
self.artTextureId = artTextureId
|
||||||
self.artInfo = artInfo
|
self.artInfo = artInfo
|
Before Width: | Height: | Size: 1.5 MiB After Width: | Height: | Size: 1.5 MiB |
BIN
ENNTool/openh264-1.7.0-win64.dll
Executable file
BIN
ENNTool/openh264-1.7.0-win64.dll
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user