Documentation ¶
Overview ¶
Package component consists of a Manager type that can load component files defined in JSON so that application assets can be defined outside of the binary.
Once a Component is loaded it can be used as a prototype to clone new Renderable instances from so that multiple objects can be rendered using the same OpenGL buffers to define model data.
Index ¶
- Constants
- func CreateRenderableForMesh(tm *fizzle.TextureManager, shaders map[string]*fizzle.RenderShader, ...) *fizzle.Renderable
- type ChildRef
- type CollisionRef
- type Component
- type Manager
- func (cm *Manager) AddComponent(name string, component *Component)
- func (cm *Manager) Destroy()
- func (cm *Manager) GetComponent(name string) (*Component, bool)
- func (cm *Manager) GetRenderableInstance(component *Component) *fizzle.Renderable
- func (cm *Manager) LoadComponentFromBytes(jsonBytes []byte, storageName string, componentDirPath string) (*Component, error)
- func (cm *Manager) LoadComponentFromFile(filename string, storageName string) (*Component, error)
- type Material
- type Mesh
Constants ¶
const ( // ColliderTypeAABB is for axis aligned bounding box colliders. ColliderTypeAABB = 0 // ColliderTypeSphere is for sphere colliders. ColliderTypeSphere = 1 // ColliderTypeCount is the number of collider types supported. ColliderTypeCount = 2 )
Variables ¶
This section is empty.
Functions ¶
func CreateRenderableForMesh ¶ added in v0.2.0
func CreateRenderableForMesh(tm *fizzle.TextureManager, shaders map[string]*fizzle.RenderShader, compMesh *Mesh) *fizzle.Renderable
CreateRenderableForMesh does the work of creating the Renderable and putting all of the mesh data into VBOs. This also creates a new material for the renderable and assigns the textures accordingly.
Types ¶
type ChildRef ¶ added in v0.3.0
type ChildRef struct { // File is the component file to load as a child object and the location should // be relative to the main component's file path. File string // Location is the location of the child object in the component. Location mgl.Vec3 // RotationAxis is the axis by which to rotate the child component around; this // is only valid if RotationDegrees is non-zero. RotationAxis mgl.Vec3 // RotationDegrees is the amount of rotation to apply to this child component along // the axis specified by RotationAxis. RotationDegrees float32 // Scale is the scaling vector for the child component in the component. Scale mgl.Vec3 }
ChildRef defines a reference to another component JSON file so that Components can be built from other Component parts.
type CollisionRef ¶
type CollisionRef struct { // Type is the type of collider from the enum above (e.g. ColliderTypeAABB, etc...). Type int8 // Min is the minimum point for AABB type colliders. Min mgl.Vec3 // Max is the maximum point for AABB type colliders. Max mgl.Vec3 // Radius is the size of the Sphere type of collider. Radius float32 // Offset is used as the offset for Sphere and AABB types of colliders. Offset mgl.Vec3 // Tags is a way to create 'layers' of colliders so that client code // can select whether or not to attempt collision against this object. Tags []string }
CollisionRef specifies a collision object within the component (e.g. a collision cube for a wall). It acts as a kind of union structure for different collider properties.
type Component ¶
type Component struct { // Name is the name of the component. Name string // Location is the location of the component in world-space coordinates. // This can be viewed as a kind-of default value. Location mgl.Vec3 // Meshes is a slice of the meshes that are parts of this component. Meshes []*Mesh // ChildReferences can be specified to include other components // to be contained in this component. ChildReferences []*ChildRef // Collision objects for the component; currently the fizzle library doesn't // do anything specific with this and choice of collision library is left to // the user. Collisions []*CollisionRef // Properties is a map for client code's custom properties for the component. Properties map[string]string // contains filtered or unexported fields }
Component is the main structure that defines a component and also defines what fields to use in component JSON files.
func (*Component) Clone ¶
Clone makes a new component and then copies the members over to the new object. This means that Meshes, Collisions, ChildReferences, etc... are shared between the clones.
func (*Component) Destroy ¶
func (c *Component) Destroy()
Destroy will destroy the cached Renderable object if it exists.
func (*Component) GetRenderable ¶
func (c *Component) GetRenderable(tm *fizzle.TextureManager, shaders map[string]*fizzle.RenderShader) *fizzle.Renderable
GetRenderable will return the cached renderable object for the component or create one if it hasn't been made yet. The TextureManager is needed to resolve texture references and the shaders collection is needed to set a RenderShader identified by the name defined in Component.
NOTE: This is not an instance of the renderable, but the main renderable object for the component.
func (*Component) SetRenderable ¶
func (c *Component) SetRenderable(newRenderable *fizzle.Renderable)
SetRenderable sets the cached renderable to the one passed in as a parameter, calling Destroy() on the already exisiting cached Renderable.
type Manager ¶ added in v0.3.0
type Manager struct {
// contains filtered or unexported fields
}
Manager loads and manages access to Component objects. Component files are defined in JSON notation which is a serialized version of Component.
func NewManager ¶ added in v0.3.0
func NewManager(tm *fizzle.TextureManager, shaders map[string]*fizzle.RenderShader) *Manager
NewManager creates a new Manager object using the the texture manager and shader collection specified.
func (*Manager) AddComponent ¶ added in v0.3.0
AddComponent adds a new component to the collection. If one existed previous using the same name, then it is overwritten.
func (*Manager) Destroy ¶ added in v0.3.0
func (cm *Manager) Destroy()
Destroy will destroy all of the contained Component objects and reset the component storage map.
func (*Manager) GetComponent ¶ added in v0.3.0
GetComponent returns a component from storage that matches the name specified. A bool is returned as the second value to indicate whether or not the component was found in storage.
func (*Manager) GetRenderableInstance ¶ added in v0.3.0
func (cm *Manager) GetRenderableInstance(component *Component) *fizzle.Renderable
GetRenderableInstance gets the renderable from the component and clones it to a new instance. It then loops over all child references and calls GetRenderableInstance for all of them, creating new clones for each, recursively.
func (*Manager) LoadComponentFromBytes ¶ added in v0.3.0
func (cm *Manager) LoadComponentFromBytes(jsonBytes []byte, storageName string, componentDirPath string) (*Component, error)
LoadComponentFromBytes loads the component from a JSON byte slice and stores it under the name specified. componentDirPath can be set to aid the finding of parts of the component to load. This function returns the new component and a possible error value.
func (*Manager) LoadComponentFromFile ¶ added in v0.3.0
LoadComponentFromFile loads a component from a JSON file and stores it under the name speicified. This function returns the new component and a possible error value.
type Material ¶ added in v0.3.0
type Material struct { // ShaderName is the name of the shader program to use for rendering. ShaderName string // Diffuse is the base color for the material. Diffuse mgl.Vec4 // Specular is the highlight color for the material. Specular mgl.Vec4 // Shininess is how shiny the material is. // Setting to 0 removes the specular effect. Shininess float32 // GenerateMipmaps indicates if mipmaps should be generated for the textures getting loaded. GenerateMipmaps bool // DiffuseTexture is the relative file path for the diffuse texture. DiffuseTexture string // NormalsTexture is the relative file path for the normal map texture. NormalsTexture string // SpecularTexture is the relative file path for the specular map texture. SpecularTexture string // Textures specifies the texture files to load for mesh, relative // to the component file. They will be found to RenderableCore // Tex* properties in order defined. Textures []string }
Material defines the visual appearance of the component.
type Mesh ¶ added in v0.3.0
type Mesh struct { // Name is the user identifier for the mesh in the component. Name string // The material describes visual attirbutes of the component. Material Material // SrcFile is a filepath, relative to the component file, // for the source binary of the model to load. SrcFile string // BinFile is a filepath should be relative to component file // for the Gombz binary of the model to load. BinFile string // Offset is the location offset of the mesh in the component // specified in local coordinates. Offset mgl.Vec3 // Scale is the scaling vector for the mesh in the component. Scale mgl.Vec3 // RotationAxis is the axis by which to rotate the mesh around; this // is only valid if RotationDegrees is non-zero. RotationAxis mgl.Vec3 // RotationDegrees is the amount of rotation to apply to this mesh along // the axis specified by RotationAxis. RotationDegrees float32 // Parent is the owning Component object, if any. Parent *Component `json:"-"` // SrcMesh is the cached mesh data either from BinFile. SrcMesh *gombz.Mesh `json:"-"` }
Mesh defines a mesh reference for a component and everything needed to draw it.
func NewMesh ¶ added in v0.3.0
func NewMesh() *Mesh
NewMesh creates a new Mesh object with sane defaults.
func (*Mesh) GetFullBinFilePath ¶ added in v0.3.0
GetFullBinFilePath returns the full file path for the mesh binary file (gombz format).
func (*Mesh) GetFullTexturePath ¶ added in v0.3.0
GetFullTexturePath returns the full file path for the mesh texture. The textureIndex is an index into Mesh.Textures to pull the texture name to build the path for.