Skip to content

package kaiju_mesh

import "kaijuengine.com/rendering/loaders/kaiju_mesh"

Functions

IsGLB

func IsGLB(data []byte) bool

MeshRefString

func MeshRefString(asset, key string) string

StableMeshKey

func StableMeshKey(name string, index int, used map[string]int) string

Types

AnimBone

struct

type AnimBone struct {
    NodeIndex     int
    PathType      AnimationPathType
    Interpolation AnimationInterpolation
    // Could be Vec3 or Quaternion, doing this because Go doesn't have a union
    Data [4]matrix.Float
}

AnimKeyFrame

struct

type AnimKeyFrame struct {
    Bones []AnimBone
    Time  float32
}

AnimationInterpolation

int

type AnimationInterpolation = int

const ( AnimInterpolateInvalid AnimationInterpolation = iota - 1 AnimInterpolateLinear AnimInterpolateStep AnimInterpolateCubicSpline )

AnimationPathType

int

type AnimationPathType = int

const ( AnimPathInvalid AnimationPathType = iota - 1 AnimPathTranslation AnimPathRotation AnimPathScale AnimPathWeights )

KaijuMesh

struct

type KaijuMesh struct {
    Key        string
    Name       string
    Node       KaijuMeshNode
    Material   string
    Verts      []rendering.Vertex
    Indexes    []uint32
    Textures   map[string]string
    BVH        *graviton.TriangleBVH
    Animations []KaijuMeshAnimation
    Joints     []KaijuMeshJoint
}

KaijuMesh is a base primitive representing a single mesh. This is the archived format of the authored meshes. Typically this structure is created by loading in a mesh using something like [loaders.GLTF] and then converting the result of that using LoadedResultToKaijuMesh. From this point, it is typically serialized and stored into the content database. When reading a mesh from the content database, it will return a KaijuMesh.

Deserialize

func Deserialize(data []byte) (KaijuMesh, error)

Deserialize will construct a KaijuMesh from the given array of bytes. This supports GLB mesh content and falls back to native/gob for legacy assets.

LoadedResultToKaijuMesh

func LoadedResultToKaijuMesh(res load_result.Result) []KaijuMesh

LoadedResultToKaijuMesh will take in a load_result.Result and convert every mesh contained within the structure to our built in version known as KaijuMesh. This is typically used for the editor, but games/applications may find some use for it.

ReadMesh

func ReadMesh(ref string, host *engine.Host) (KaijuMesh, error)

KaijuMesh.EnsureBVH

func (k *KaijuMesh) EnsureBVH()

KaijuMesh.GenerateBVH

func (k *KaijuMesh) GenerateBVH(threads *concurrent.Threads, transform *matrix.Transform, data any) *graviton.BVH

KaijuMesh.GenerateBVHArchive

func (k *KaijuMesh) GenerateBVHArchive() *graviton.TriangleBVH

KaijuMesh.Serialize

func (k KaijuMesh) Serialize() ([]byte, error)

Serialize will convert a KaijuMesh into a byte array for saving to the database or later use.

KaijuMesh.SerializeWithOptions

func (k KaijuMesh) SerializeWithOptions(options SerializeOptions) ([]byte, error)

KaijuMeshAnimation

struct

type KaijuMeshAnimation struct {
    Name   string
    Frames []AnimKeyFrame
}

KaijuMeshJoint

struct

type KaijuMeshJoint struct {
    Id       int32
    Parent   int32
    Skin     matrix.Mat4
    Position matrix.Vec3
    Rotation matrix.Vec3
    Scale    matrix.Vec3
}

KaijuMeshNode

struct

type KaijuMeshNode struct {
    Name     string
    Position matrix.Vec3
    Rotation matrix.Vec3
    Scale    matrix.Vec3
}

KaijuMeshSet

struct

type KaijuMeshSet struct {
    Name   string
    Meshes []KaijuMesh
}

DeserializeSet

func DeserializeSet(data []byte) (KaijuMeshSet, error)

LoadedResultToKaijuMeshSet

func LoadedResultToKaijuMeshSet(name string, res load_result.Result) KaijuMeshSet

KaijuMeshSet.EnsureBVH

func (s KaijuMeshSet) EnsureBVH()

KaijuMeshSet.MeshByKey

func (s KaijuMeshSet) MeshByKey(key string) (KaijuMesh, bool)

KaijuMeshSet.Serialize

func (s KaijuMeshSet) Serialize() ([]byte, error)

KaijuMeshSet.SerializeWithOptions

func (s KaijuMeshSet) SerializeWithOptions(options SerializeOptions) ([]byte, error)

MeshRef

struct

type MeshRef struct {
    Asset string
    Key   string
}

ParseMeshRef

func ParseMeshRef(ref string) MeshRef

MeshRef.IsSubmesh

func (r MeshRef) IsSubmesh() bool

MeshRef.String

func (r MeshRef) String() string

SerializeOptions

struct

type SerializeOptions struct {
    TextureURIs     map[string]string
    MeshTextureURIs map[string]map[string]string
}