Skip to content

Commit

Permalink
Renaming alpha-ordering example to compositing.
Browse files Browse the repository at this point in the history
Renaming Camera.DrawDebugText() > DrawDebugRenderInfo().
Updating documentation, adding missing documentation for INode.
Removing casts from NodeFilter filtering functions, as they're unnecessary.
  • Loading branch information
SolarLune committed Jul 19, 2022
1 parent 2081a4a commit 2afa8fc
Show file tree
Hide file tree
Showing 29 changed files with 175 additions and 137 deletions.
12 changes: 7 additions & 5 deletions camera.go
Original file line number Diff line number Diff line change
Expand Up @@ -1198,9 +1198,9 @@ func (camera *Camera) drawCircle(screen *ebiten.Image, position vector.Vector, r

}

// DrawDebugText draws render debug information (like number of drawn objects, number of drawn triangles, frame time, etc)
// DrawDebugRenderInfo draws render debug information (like number of drawn objects, number of drawn triangles, frame time, etc)
// at the top-left of the provided screen *ebiten.Image, using the textScale and color provided.
func (camera *Camera) DrawDebugText(screen *ebiten.Image, textScale float64, color *Color) {
func (camera *Camera) DrawDebugRenderInfo(screen *ebiten.Image, textScale float64, color *Color) {

m := camera.DebugInfo.AvgFrameTime.Round(time.Microsecond).Microseconds()
ft := fmt.Sprintf("%.2fms", float32(m)/1000)
Expand All @@ -1225,7 +1225,7 @@ func (camera *Camera) DrawDebugText(screen *ebiten.Image, textScale float64, col
camera.DebugInfo.ActiveLightCount,
camera.DebugInfo.LightCount)

camera.DebugDrawText(screen, debugText, 0, textScale*16, textScale, color)
camera.DebugDrawText(screen, debugText, 0, 0, textScale, color)

}

Expand Down Expand Up @@ -1432,12 +1432,14 @@ func (camera *Camera) DebugDrawText(screen *ebiten.Image, txtStr string, posX, p
dr := &ebiten.DrawImageOptions{}
dr.ColorM.Scale(0, 0, 0, 1)

periodOffset := 8.0

for y := -1; y < 2; y++ {

for x := -1; x < 2; x++ {

dr.GeoM.Reset()
dr.GeoM.Translate(posX+4+float64(x), posY+(textScale*16)+4+float64(y))
dr.GeoM.Translate(posX+4+float64(x), posY+4+float64(y)+periodOffset)
dr.GeoM.Scale(textScale, textScale)

text.DrawWithOptions(screen, txtStr, basicfont.Face7x13, dr)
Expand All @@ -1449,7 +1451,7 @@ func (camera *Camera) DebugDrawText(screen *ebiten.Image, txtStr string, posX, p
dr.ColorM.Scale(color.ToFloat64s())

dr.GeoM.Reset()
dr.GeoM.Translate(posX+4, posY+(textScale*16)+4)
dr.GeoM.Translate(posX+4, posY+4+periodOffset)
dr.GeoM.Scale(textScale, textScale)

text.DrawWithOptions(screen, txtStr, basicfont.Face7x13, dr)
Expand Down
Binary file removed examples/alpha-ordering/alpha-ordering.blend
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/animatedTextures/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
}

if g.DrawDebugText {
g.Camera.DrawDebugText(screen, 1, colors.White())
g.Camera.DrawDebugRenderInfo(screen, 1, colors.White())
txt := "F1 to toggle this text\nWASD: Move, Mouse: Look\n\nThis demo shows how animated textures and billboarding work.\nThere are several lava planes, but they all share\nthe same mesh, which is animated by the\nTexturePlayer.\n\nThe character faces the camera because his\nmaterial has its BillboardMode set to X/Z (so\nit faces the camera, but doesn't tilt horizontally).\n1 key: Toggle playback\n\nF2:Toggle wireframe\nF5: Toggle depth debug view\nF4: Toggle fullscreen\nESC: Quit"
text.Draw(screen, txt, basicfont.Face7x13, 0, 140, color.RGBA{200, 200, 200, 255})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/animations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
}

if g.DrawDebugText {
g.Camera.DrawDebugText(screen, 1, colors.White())
g.Camera.DrawDebugRenderInfo(screen, 1, colors.White())
txt := "F1 to toggle this text\nWASD: Move, Mouse: Look\n1 Key: Play [SmoothRoll] Animation On Table\n2 Key: Play [StepRoll] Animation on Table\nNote the animations can blend\nF Key: Play Animation on Skinned Mesh\nNote that the nodes move as well\nF4: Toggle fullscreen\nF6: Node Debug View\nESC: Quit"
text.Draw(screen, txt, basicfont.Face7x13, 0, 140, color.RGBA{255, 0, 0, 255})
}
Expand Down
4 changes: 2 additions & 2 deletions examples/bounds/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (g *Game) Update() error {
bounds := g.Controlling.Children()[0].(tetra3d.BoundingObject)

// Above, we move the objects into place as necessary, so we don't need to use the dx, dy, and dz arguments to test for movement when doing the CollisionTest.
for _, col := range bounds.CollisionTest(0, 0, 0, g.Scene.Root.ChildrenRecursive().ByType(tetra3d.NodeTypeBounding).AsBoundingObjects()...) {
for _, col := range bounds.CollisionTest(0, 0, 0, g.Scene.Root.ChildrenRecursive().ByType(tetra3d.NodeTypeBoundingObject).AsBoundingObjects()...) {
g.Controlling.MoveVec(col.AverageMTV())
}

Expand Down Expand Up @@ -247,7 +247,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
}

if g.DrawDebugText {
g.Camera.DrawDebugText(screen, 1, colors.White())
g.Camera.DrawDebugRenderInfo(screen, 1, colors.White())
shapeName := g.Controlling.Name()
txt := "F1 to toggle this text\nWASD: Move, Mouse: Look\nArrow keys: Move " + shapeName + "\nF: switch between capsule and sphere\nF1, F2, F3: Debug views\nF5: Display bounds shapes\nF4: Toggle fullscreen\nESC: Quit"
text.Draw(screen, txt, basicfont.Face7x13, 0, 140, color.RGBA{192, 192, 192, 255})
Expand Down
File renamed without changes
Binary file added examples/compositing/compositing.blend
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"asset" : {
"generator" : "Khronos glTF Blender I/O v1.8.19",
"generator" : "Khronos glTF Blender I/O v3.2.43",
"version" : "2.0"
},
"extensionsUsed" : [
Expand Down Expand Up @@ -59,12 +59,12 @@
},
"name" : "Scene",
"nodes" : [
0,
1,
2,
3,
4,
5,
6
5
]
}
],
Expand All @@ -75,18 +75,6 @@
"light" : 0
}
},
"name" : "Light_Orientation",
"rotation" : [
-0.7071067690849304,
0,
0,
0.7071067690849304
]
},
{
"children" : [
0
],
"extras" : {
"t3dOriginalLocalPosition__" : [
4.076245307922363,
Expand All @@ -96,10 +84,10 @@
},
"name" : "Light",
"rotation" : [
0.16907575726509094,
0.7558803558349609,
-0.27217137813568115,
0.570947527885437
-0.2841663062572479,
0.7269423604011536,
0.34203392267227173,
0.5232754349708557
],
"translation" : [
4.076245307922363,
Expand Down
37 changes: 18 additions & 19 deletions examples/alpha-ordering/main.go → examples/compositing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"fmt"
"image/color"
"image/png"
"math"
"os"
Expand All @@ -16,11 +15,9 @@ import (
"github.com/kvartborg/vector"
"github.com/solarlune/tetra3d"
"github.com/solarlune/tetra3d/colors"
"golang.org/x/image/font/basicfont"

"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/hajimehoshi/ebiten/v2/text"
)

type Game struct {
Expand All @@ -38,8 +35,8 @@ type Game struct {
BG *ebiten.Image
}

//go:embed alpha-ordering.gltf
var alphaOrdering []byte
//go:embed compositing.gltf
var compositingGLTF []byte

//go:embed bg.png
var bgPng []byte
Expand All @@ -58,24 +55,24 @@ func NewGame() *Game {
}

func (g *Game) Init() {
data, err := tetra3d.LoadGLTFData(alphaOrdering, nil)

// Load the GLTF.
data, err := tetra3d.LoadGLTFData(compositingGLTF, nil)
if err != nil {
panic(err)
}

g.Scene = data.Scenes[0]
g.Scene = data.Scenes[0].Clone()

// Load the background image.
br := bytes.NewReader(bgPng)
img, err := png.Decode(br)
if err != nil {
panic(err)
}
g.BG = ebiten.NewImageFromImage(img)

// This is another way to do it
// screen := g.Scene.Root.Get("Screen").(*tetra3d.Model)
// screen.Mesh.FindMeshPartByMaterialName("ScreenTexture").Material.Image = g.Offscreen

// Set up a camera.
g.Camera = tetra3d.NewCamera(g.Width, g.Height)
g.Camera.SetLocalPosition(vector.Vector{0, 0, 5})
g.Scene.Root.AddChildren(g.Camera)
Expand Down Expand Up @@ -191,23 +188,25 @@ func (g *Game) Draw(screen *ebiten.Image) {
// Clear the Camera
g.Camera.Clear()

// Render the scene
g.Camera.RenderNodes(g.Scene, g.Scene.Root)

// We rescale the depth or color textures here just in case we render at a different resolution than the window's; this isn't necessary,
// we could just draw the images straight.
opt = &ebiten.DrawImageOptions{}
w, h = g.Camera.ColorTexture().Size()
opt.GeoM.Scale(float64(g.Width)/float64(w), float64(g.Height)/float64(h))

if g.DrawDebugDepth {
screen.DrawImage(g.Camera.DepthTexture(), opt)
screen.DrawImage(g.Camera.DepthTexture(), nil)
} else {
screen.DrawImage(g.Camera.ColorTexture(), opt)
// Draw the output
screen.DrawImage(g.Camera.ColorTexture(), nil)
}

if g.DrawDebugText {
g.Camera.DrawDebugText(screen, 1, colors.White())
txt := "F1 to toggle this text\nWASD: Move, Mouse: Look\nThis demo shows how composite modes work.\nThe blue plane is opaque.\nThe red one is additive.\nThe green one is transparent.\nThe closest plane cuts out all objects to show the background.\n\nF5: Toggle depth debug view\nF4: Toggle fullscreen\nESC: Quit"
text.Draw(screen, txt, basicfont.Face7x13, 0, 130, color.RGBA{255, 0, 0, 255})
g.Camera.DrawDebugRenderInfo(screen, 1, colors.White())
g.Camera.DebugDrawText(screen,
"F1 to toggle this text\nWASD: Move, Mouse: Look\nThis demo shows how composite modes work.\nThe blue plane is opaque.\nThe red one is additive.\nThe green one is transparent.\nThe closest plane cuts out all objects to show the background.\n\nF5: Toggle depth debug view\nF4: Toggle fullscreen\nESC: Quit",
0, 150, 1, colors.Red(),
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/engine/gameobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (player *Player) Update() {

movementResolution := vector.Vector{0, 0, 0}

for _, b := range player.node.Root().ChildrenRecursive().ByType(tetra3d.NodeTypeBounding) {
for _, b := range player.node.Root().ChildrenRecursive().ByType(tetra3d.NodeTypeBoundingObject) {
bounds := b.(tetra3d.BoundingObject)

if result := playerBounds.Collision(bounds); result != nil {
Expand Down
2 changes: 1 addition & 1 deletion examples/engine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
}

if g.DrawDebugText {
g.Camera.DrawDebugText(screen, 1, colors.White())
g.Camera.DrawDebugRenderInfo(screen, 1, colors.White())
txt := "F1 to toggle this text\nWASD: Move, Mouse: Look\n\nThis demo is a small example showing how one could design a game\nusing a traditional 'class-based' approach with Tetra3D.\n\n1 Key: Spawn player objects.\nArrow keys: Move player(s)\nTouch spikes to destroy player(s)\n\nF5: Toggle depth debug view\nF4: Toggle fullscreen\nESC: Quit"
text.Draw(screen, txt, basicfont.Face7x13, 0, 120, color.RGBA{200, 200, 200, 255})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (g *Game) Draw(screen *ebiten.Image) {

if g.DrawDebugText {
g.Camera.DrawDebugFrustums(screen, g.Scene.Root, colors.White())
g.Camera.DrawDebugText(screen, 1, colors.White())
g.Camera.DrawDebugRenderInfo(screen, 1, colors.White())
txt := "F1 to toggle this text\nWASD: Move, Mouse: Look\nThis example simply shows dynamic vertex-based lighting.\nThere are six lights in this scene:\nan ambient light, three point lights, \na single directional (sun) light,\nand one more point light parented to the camera.\n1 Key: Toggle all lighting\n2 Key: Toggle camera light\nF5: Toggle depth debug view\nF4: Toggle fullscreen\nESC: Quit"
text.Draw(screen, txt, basicfont.Face7x13, 0, 150, color.RGBA{255, 0, 0, 255})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/logo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
}

if g.DrawDebugText {
g.Camera.DrawDebugText(screen, 1, colors.White())
g.Camera.DrawDebugRenderInfo(screen, 1, colors.White())
txt := "F1 to toggle this text\nWASD: Move, Mouse: Look\nThe screen object shows what the\ncamera is looking at.\nF5: Toggle depth debug view\nF4: Toggle fullscreen\nESC: Quit"
text.Draw(screen, txt, basicfont.Face7x13, 0, 120, color.RGBA{200, 200, 200, 255})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/orthographic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
}

if g.DrawDebugText {
camera.DrawDebugText(screen, 1, colors.White())
camera.DrawDebugRenderInfo(screen, 1, colors.White())
txt := "F1 to toggle this text\nArrow Keys: Pan in cardinal directions\nW, S: Zoom in and Out\nQ, E: Rotate View\nR: Restart\nF4: Toggle fullscreen\nESC: Quit"
text.Draw(screen, txt, basicfont.Face7x13, 0, 128, color.RGBA{255, 0, 0, 255})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/parenting/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
}

if g.DrawDebugText {
g.Camera.DrawDebugText(screen, 1, colors.White())
g.Camera.DrawDebugRenderInfo(screen, 1, colors.White())
}

if g.DrawDebugWireframe {
Expand Down
2 changes: 1 addition & 1 deletion examples/paths/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
}

if g.DrawDebugText {
g.Camera.DrawDebugText(screen, 1, colors.White())
g.Camera.DrawDebugRenderInfo(screen, 1, colors.White())
txt := "F1 to toggle this text\nWASD: Move, Mouse: Look\n\nThis demo shows how paths work.\nThe cube will follow the path (which is invisible,\nas it is made up of Nodes).\n1 key: Toggle running through path\nLeft, Right keys: Step 1 unit forward or\nback through the path\n\nF2:Toggle wireframe\nF5: Toggle depth debug view\nF4: Toggle fullscreen\nESC: Quit"
text.Draw(screen, txt, basicfont.Face7x13, 0, 130, color.RGBA{255, 0, 0, 255})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/properties/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
}

if g.DrawDebugText {
g.Camera.DrawDebugText(screen, 1, colors.White())
g.Camera.DrawDebugRenderInfo(screen, 1, colors.White())
txt := "F1 to toggle this text\nWASD: Move, Mouse: Look\n\nThis demo shows how game properties work with\nthe Tetra3D Blender add-on.\nGame properties are set in the blend file, and\nexported from there to a GLTF file.\nThey become tags here in Tetra3D,\ninfluencing whether the cubes rotate or float,\nand at what speed.\n\nF5: Toggle depth debug view\nF4: Toggle fullscreen\nESC: Quit"
text.Draw(screen, txt, basicfont.Face7x13, 0, 120, color.RGBA{200, 200, 200, 255})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/shader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
}

if g.DrawDebugText {
g.Camera.DrawDebugText(screen, 1, colors.White())
g.Camera.DrawDebugRenderInfo(screen, 1, colors.White())
txt := "F1 to toggle this text\nWASD: Move, Mouse: Look\nThis demo shows how custom shaders work.\nThere are two kinds: fragment shaders and vertex programs.\nFragment shaders are written in Kage, while\nvertex programs are written in pure Go and are\ndone on the CPU.\nThe cube on the left is running a fragment shader,\nwhile the cube on the right runs a vertex program.\nF5: Toggle depth debug view\nF4: Toggle fullscreen\nESC: Quit"
text.Draw(screen, txt, basicfont.Face7x13, 0, 120, color.RGBA{255, 0, 0, 255})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/shapes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
}

if g.DrawDebugText {
g.Camera.DrawDebugText(screen, 1, tetra3d.NewColor(0, 0.5, 1, 1))
g.Camera.DrawDebugRenderInfo(screen, 1, tetra3d.NewColor(0, 0.5, 1, 1))
txt := "F1 to toggle this text\nWASD: Move, Mouse: Look\n1, 2, 3, 4: Change fog\nF1, F2, F3, F5: Debug views\nF4: Toggle fullscreen\nESC: Quit"
text.Draw(screen, txt, basicfont.Face7x13, 0, 128, color.RGBA{255, 0, 0, 255})
}
Expand Down
Loading

0 comments on commit 2afa8fc

Please sign in to comment.