gorube

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2020 License: MIT Imports: 5 Imported by: 0

README

Go R.U.B.E Scene Loader

  • Load JSON scene files from R.U.B.E Box2D editor
  • Generate Box2D types for Box2D.go physics engine

Package import

import "github.com/SmoothLab/gorube"

Loading R.U.B.E scenes

Load a JSON file :

scene, err := gorube.LoadJSONFile("scene.json")
if err != nil {
    panic(err)
}

Load JSON data :

var d []bytes = ...
scene := gorube.LoadJSONData(d)

Load a JSON string :

var s string = ...
scene := gorube.LoadJSONString(s)

The resulting scene is a structure containing definitions for :

  • World
  • Bodies
  • Joints
  • Images
  • Objects
  • ...

Generating Box2D types

Create world, bodies and joints from a scene in one shot :

world, bodies, joints := scene.CreateB2WorldBodiesJoints()

Create world, bodies and joints independently :

world  := scene.CreateB2World()
bodies := scene.CreateB2Bodies(world)
joints := scene.CreateB2Joints(world, bodies)

Scene entities can generate specific Box2D types :

  • Body → B2BodyDef
  • Fixture → B2FixtureDef
  • Filter → B2Filter
  • Shape → B2Shape
  • Joint → B2JointDef
  • Vector → B2Vec2

Custom properties

R.U.B.E allows creation of named custom properties on a Scene, Body, Fixture, Joint, Image and Object.

They can have different types :

  • bool
  • int
  • float
  • string
  • Vector
  • Color

Access a boolean custom property on a scene :

smooth, ok := scene.CustomProperties().GetBool("smooth")

Same, setting a default value if the property does not exist :

smooth := scene.CustomProperties().GetBoolDefault("smooth", true)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateB2Vec2Array

func CreateB2Vec2Array(va []Vector) []box2d.B2Vec2

CreateB2Vec2Array func

Types

type Body

type Body struct {
	Active           bool
	AllowSleep       bool
	Angle            float64
	AngularDamping   float64
	AngularVelocity  float64
	Awake            bool
	Bullet           bool
	CustomProperties CustomProperties
	FixedRotation    bool
	Fixtures         []Fixture
	GravityScale     float64
	LinearDamping    float64
	LinearVelocity   Vector
	MassData         MassData
	Name             string
	Position         Vector
	Type             BodyType
}

Body type

func (Body) CreateB2BodyDef

func (b Body) CreateB2BodyDef() *box2d.B2BodyDef

CreateB2BodyDef func

type BodyType

type BodyType int

BodyType type

const (
	DynamicType BodyType = iota
	KinematicType
	StaticType
)

BodyType const

func (BodyType) CreateB2BodyType

func (bt BodyType) CreateB2BodyType() uint8

CreateB2BodyType func

type ChainShapeProperties

type ChainShapeProperties struct {
	HasNextVertex bool
	HasPrevVertex bool
	NextVertex    Vector
	PrevVertex    Vector
	Vertices      []Vector
}

ChainShapeProperties type

type CircleShapeProperties

type CircleShapeProperties struct {
	Position Vector
	Radius   float64
}

CircleShapeProperties type

type Color

type Color struct {
	Alpha int
	Blue  int
	Green int
	Red   int
}

Color type

type CustomProperties

type CustomProperties map[string]interface{}

CustomProperties type

func (CustomProperties) GetBool

func (cp CustomProperties) GetBool(name string) (bool, bool)

GetBool func

func (CustomProperties) GetBoolDefault

func (cp CustomProperties) GetBoolDefault(name string, defaultValue bool) bool

GetBoolDefault func

func (CustomProperties) GetColor

func (cp CustomProperties) GetColor(name string) (Color, bool)

GetColor func

func (CustomProperties) GetColorDefault

func (cp CustomProperties) GetColorDefault(name string, defaultValue Color) Color

GetColorDefault func

func (CustomProperties) GetFloat

func (cp CustomProperties) GetFloat(name string) (float64, bool)

GetFloat func

func (CustomProperties) GetFloatDefault

func (cp CustomProperties) GetFloatDefault(name string, defaultValue float64) float64

GetFloatDefault func

func (CustomProperties) GetInt

func (cp CustomProperties) GetInt(name string) (int, bool)

GetInt func

func (CustomProperties) GetIntDefault

func (cp CustomProperties) GetIntDefault(name string, defaultValue int) int

GetIntDefault func

func (CustomProperties) GetString

func (cp CustomProperties) GetString(name string) (string, bool)

GetString func

func (CustomProperties) GetStringDefault

func (cp CustomProperties) GetStringDefault(name string, defaultValue string) string

GetStringDefault func

func (CustomProperties) GetVector

func (cp CustomProperties) GetVector(name string) (Vector, bool)

GetVector func

func (CustomProperties) GetVectorDefault

func (cp CustomProperties) GetVectorDefault(name string, defaultValue Vector) Vector

GetVectorDefault func

type CustomProperty

type CustomProperty struct {
	Name  string
	Type  CustomPropertyType
	Value interface{}
}

CustomProperty type

type CustomPropertyType

type CustomPropertyType int

CustomPropertyType type

const (
	BoolType CustomPropertyType = iota
	ColorType
	FloatType
	IntType
	StringType
	VectorType
)

CustomPropertyType const

type DistanceJointProperties

type DistanceJointProperties struct {
	DampingRatio float64
	Frequency    float64
	Length       float64
}

DistanceJointProperties type

type Filter

type Filter struct {
	CategoryBits int
	GroupIndex   int
	MaskBits     int
}

Filter type

func (Filter) CreateB2Filter

func (f Filter) CreateB2Filter() box2d.B2Filter

CreateB2Filter func

type Fixture

type Fixture struct {
	CustomProperties CustomProperties
	Density          float64
	Filter           Filter
	Friction         float64
	IsSensor         bool
	Name             string
	Restitution      float64
	Shape            Shape
}

Fixture type

func (Fixture) CreateB2FixtureDef

func (f Fixture) CreateB2FixtureDef() *box2d.B2FixtureDef

CreateB2FixtureDef func

type FrictionJointProperties

type FrictionJointProperties struct {
	MaxForce  float64
	MaxTorque float64
}

FrictionJointProperties type

type Image

type Image struct {
	Angle             float64
	AspectScale       float64
	Body              int
	Center            Vector
	ColorTint         Color
	Corners           []Vector
	CustomProperties  CustomProperties
	File              string
	Filter            ImageFilter
	Flip              bool
	GlDrawElements    []int
	GlTexCoordPointer []int
	GlVertexPointer   []float64
	Name              string
	Opacity           float64
	RenderOrder       float64
	Scale             float64
}

Image type

type ImageFilter

type ImageFilter int

ImageFilter type

const (
	LinearFilter ImageFilter = iota
	NearestFilter
)

ImageFilter const

type Joint

type Joint struct {
	BodyA            int
	BodyB            int
	CollideConnected bool
	CustomProperties CustomProperties
	LocalAnchorA     Vector
	LocalAnchorB     Vector
	Name             string
	Properties       interface{}
	Type             JointType
}

Joint type

func (Joint) CreateB2JointDef

func (j Joint) CreateB2JointDef(bodies []*box2d.B2Body) box2d.B2JointDefInterface

CreateB2JointDef func

type JointType

type JointType int

JointType type

const (
	DistanceType JointType = iota
	FrictionType
	MotorType
	PrismaticType
	RevoluteType
	RopeType
	WeldType
	WheelType
)

JointType const

type MassData

type MassData struct {
	Center  Vector
	Inertia float64
	Mass    float64
}

MassData type

type MotorJointProperties

type MotorJointProperties struct {
	AngularOffset    float64
	CorrectionFactor float64
	LinearOffset     Vector
	MaxForce         float64
	MaxTorque        float64
}

MotorJointProperties type

type Object

type Object struct {
	Angle            float64
	CustomProperties CustomProperties
	Flip             bool
	Name             string
	Position         Vector
	Scale            float64
}

Object type

type PolygonShapeProperties

type PolygonShapeProperties struct {
	Vertices []Vector
}

PolygonShapeProperties type

type PrismaticJointProperties

type PrismaticJointProperties struct {
	EnableLimit      bool
	EnableMotor      bool
	LocalAxisA       Vector
	LowerTranslation float64
	MaxMotorForce    float64
	MotorSpeed       float64
	ReferenceAngle   float64
	UpperTranslation float64
}

PrismaticJointProperties type

type RevoluteJointProperties

type RevoluteJointProperties struct {
	EnableLimit    bool
	EnableMotor    bool
	LowerAngle     float64
	MaxMotorTorque float64
	MotorSpeed     float64
	ReferenceAngle float64
	UpperAngle     float64
}

RevoluteJointProperties type

type RopeJointProperties

type RopeJointProperties struct {
	MaxLength float64
}

RopeJointProperties type

type Scene

type Scene struct {
	AllowSleep         bool
	AutoClearForces    bool
	Bodies             []Body
	CollisionBitPlanes []string
	ContinuousPhysics  bool
	CustomProperties   CustomProperties
	Gravity            Vector
	Images             []Image
	Joints             []Joint
	Objects            []Object
	PositionIterations int
	StepsPerSecond     float64
	SubStepping        bool
	VelocityIterations int
	WarmStarting       bool
}

Scene type

func LoadJSONData

func LoadJSONData(data []byte) Scene

LoadJSONData func

func LoadJSONFile

func LoadJSONFile(name string) (Scene, error)

LoadJSONFile func

func LoadJSONString

func LoadJSONString(string string) Scene

LoadJSONString func

func (Scene) CreateB2Bodies

func (s Scene) CreateB2Bodies(world *box2d.B2World) []*box2d.B2Body

CreateB2Bodies func

func (Scene) CreateB2BodiesJoints

func (s Scene) CreateB2BodiesJoints(world *box2d.B2World) ([]*box2d.B2Body, []*box2d.B2JointInterface)

CreateB2BodiesJoints func

func (Scene) CreateB2Joints

func (s Scene) CreateB2Joints(world *box2d.B2World, bodies []*box2d.B2Body) []*box2d.B2JointInterface

CreateB2Joints func

func (Scene) CreateB2World

func (s Scene) CreateB2World() *box2d.B2World

CreateB2World func

func (Scene) CreateB2WorldBodiesJoints

func (s Scene) CreateB2WorldBodiesJoints() (*box2d.B2World, []*box2d.B2Body, []*box2d.B2JointInterface)

CreateB2WorldBodiesJoints func

type Shape

type Shape struct {
	Properties interface{}
	Type       ShapeType
}

Shape type

func (Shape) CreateB2Shape

func (s Shape) CreateB2Shape() box2d.B2ShapeInterface

CreateB2Shape func

type ShapeType

type ShapeType int

ShapeType type

const (
	ChainType ShapeType = iota
	CircleType
	PolygonType
)

ShapeType const

type Vector

type Vector struct {
	X float64
	Y float64
}

Vector type

func (Vector) CreateB2Vec2

func (v Vector) CreateB2Vec2() box2d.B2Vec2

CreateB2Vec2 func

type WeldJointProperties

type WeldJointProperties struct {
	DampingRatio   float64
	Frequency      float64
	ReferenceAngle float64
}

WeldJointProperties type

type WheelJointProperties

type WheelJointProperties struct {
	DampingRatio   float64
	EnableMotor    bool
	Frequency      float64
	LocalAxisA     Vector
	MaxMotorTorque float64
	MotorSpeed     float64
}

WheelJointProperties type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL