rigo

package module
v0.0.0-...-aed5015 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2016 License: MIT Imports: 10 Imported by: 0

README

#RiGO license status version

NOTE: This implementation has been superceeded by version 2; which is a complete re-implementation with simpler interfaces, as such version 2 is seperate. Please use rigo2

Implementation of the RenderMan Interface for the Go programming language. This is currently based on Pixar's RenderMan Specification version 3.2.1 (November 2005). This implementation is still under active development, so expect holes and bugs.

Online Documentation

Install with:

go get github.com/mae-global/rigo

Quick example usage; outputting a Unit Cube to a RIB Entity file.

Pipeline

/* create a function to record the duration between RiBegin and RiEnd calls */
type MyTimer struct {
	start time.Time
	finish time.Time
}

func (t *MyTimer) ToRaw() ArchiveWriter {	return nil }

func (t MyTimer) Name() string {	return "mytimer" }

func (t *MyTimer) Took() time.Duration { 	return t.finish.Sub(t.start) }

func (t *MyTimer) Pipe(name RtName,args,params,values []Rter,info Info) *Result {
	switch string(name) {
		case "Begin","RiBegin":
			t.start = time.Now()
			t.finish = t.start
		break
		case "End","RiEnd":
			t.finish = time.Now()
		break
	}
	return Done()
}

/* Construct a pipeline, including our timer, piping pretty-printed RIB output to file */
pipe := NewPipe()
pipe.Append(&MyTimer{}).Append(&PipeToPrettyPrint{}).Append(&PipeToFile{})

ri := CustomEntityPipeline(pipe)

/* Do all our Ri calls */
ri.Begin("unitcube.rib")
ri.AttributeBegin("begin unit cube")
	ri.Attribute("identifier", RtToken("name"), RtToken("unitcube"))
	ri.Bound(RtBound{-.5, .5, -.5, .5, -.5, .5})
	ri.TransformBegin()

		points := RtFloatArray{.5, .5, .5, -.5, .5, .5, -.5, -.5, .5, .5, -.5, .5}

		ri.Comment("far face")
		ri.Polygon(4, RtToken("P"), points)
		ri.Rotate(90, 0, 1, 0)

		ri.Comment("right face")
		ri.Polygon(4, RtToken("P"), points)
		ri.Rotate(90, 0, 1, 0)

		ri.Comment("near face")
		ri.Polygon(4, RtToken("P"), points)
		ri.Rotate(90, 0, 1, 0)

		ri.Comment("left face")
		ri.Polygon(4, RtToken("P"), points)

	ri.TransformEnd()
	ri.TransformBegin()

		ri.Comment("bottom face")
		ri.Rotate(90, 1, 0, 0)
		ri.Polygon(4, RtToken("P"), points)

		ri.TransformEnd()
		ri.TransformBegin()

		ri.Comment("top face")
		ri.Rotate(-90, 1, 0, 0)
		ri.Polygon(4, RtToken("P"), points)

	ri.TransformEnd()
ri.AttributeEnd("end unit cube")
ri.End()	
		
/* grab our timer back and print the duration */
p = pipe.GetByName(MyTimer{}.Name())
t,_ := p.(*MyTimer)
	
fmt.Printf("took %s\n",t.Took())

RIB output of unitcube.rib is thus :-

##RenderMan RIB-Structure 1.1 Entity
AttributeBegin #begin unit cube
	Attribute "identifier" "name" "unitcube"
	Bound [-.5 .5 -.5 .5 -.5 .5]
	TransformBegin 
		# far face
		Polygon "P" [.5 .5 .5 -.5 .5 .5 -.5 -.5 .5 .5 -.5 .5]
		Rotate 90. 0 1. 0
		# right face
		Polygon "P" [.5 .5 .5 -.5 .5 .5 -.5 -.5 .5 .5 -.5 .5]
		Rotate 90. 0 1. 0
		# near face
		Polygon "P" [.5 .5 .5 -.5 .5 .5 -.5 -.5 .5 .5 -.5 .5]
		Rotate 90. 0 1. 0
		# left face
		Polygon "P" [.5 .5 .5 -.5 .5 .5 -.5 -.5 .5 .5 -.5 .5]
	TransformEnd 
	TransformBegin 
		# bottom face
		Rotate 90. 1. 0 0
		Polygon "P" [.5 .5 .5 -.5 .5 .5 -.5 -.5 .5 .5 -.5 .5]
	TransformEnd 
	TransformBegin 
		# top face
		Rotate -90. 1. 0 0
		Polygon "P" [.5 .5 .5 -.5 .5 .5 -.5 -.5 .5 .5 -.5 .5]
	TransformEnd 
AttributeEnd #end unit cube

An example light handler generator, which generates unique names so that lights can be tracked more easily.

pipe := DefaultFilePipe()
	
/* use a custom unique generator with a prefix for the light handles */
lights := NewPrefixLightUniqueGenerator("light_")
	
ctx := NewContext(pipe,lights,nil,nil,&Configuration{PrettyPrint:true})
ri := RI(ctx)
ri.Begin("output/simple.rib")
ri.Display("sphere.tif","file","rgb")
ri.Format(320,240,1)
ri.Projection(Perspective,RtToken("fov"),RtFloat(30))
ri.Translate(0,0,6)
ri.WorldBegin()
	ri.LightSource("ambientlight",RtToken("intensity"),RtFloat(0.5))
	ri.LightSource("distantlight",RtToken("intensity"),RtFloat(1.2),RtToken("from"),RtIntArray{0,0,-6},RtToken("to"),RtIntArray{0,0,0})
	ri.Color(RtColor{1,0,0})
	ri.Sphere(1,-1,1,360)
ri.WorldEnd()
ri.End()
##RenderMan RIB-Structure 1.1
version 3.04
Display "sphere.tif" "file" "rgb"
Format 320 240 1
Projection "perspective" "fov" 30
Translate 0 0 6
WorldBegin 
	LightSource "ambientlight" "light_09c84b71" "intensity" .5
	LightSource "distantlight" "light_64f4dfbf" "intensity" 1.2 "from" [0 0 -6] "to" [0 0 0]
	Color [1 0 0]
	Sphere 1 -1 1 360
WorldEnd 

Using the RIB parser to flatten the pretty printer.

pipe := DefaultFilePipe()

lights := NewPrefixLightUniqueGenerator("light_")

ctx := NewContext(pipe,lights,nil,nil,&Configuration{PrettyPrint:false})
ri := RI(ctx)
ri.Begin("output/simple_flatten.rib")

f,_ := os.Open("output/simple.rib")
defer f.Close()
ri.ParseRIB(f)

ri.End()
##RenderMan RIB-Structure 1.1
version 3.04
Display "sphere.tif" "file" "rgb"
Format 320 240 1
Projection "perspective" "fov" 30
Translate 0 0 6
WorldBegin 
LightSource "ambientlight" "light_09c84b71" "intensity" .5
LightSource "distantlight" "light_64f4dfbf" "intensity" 1.2 "from" [0 0 -6] "to" [0 0 0]
Color [1 0 0]
Sphere 1 -1 1 360
WorldEnd 

##Roadmap

  • Regression tests
    • Basic RIB outputs against expected
    • Image Comparsion against expected -- tiffdiff
    • RIB output comparsion from PRMan
  • Ability to run an output to an application from RiBegin
  • Structure block for recording context settings in RIB output Moved to tools (outside of this package)
  • Basic RIB pipe
  • Complete RenderMan Interface
  • Filters
    • Inline replacement
    • RIB outputer
  • Stdout/buffer wrapper around io.Writer interface
  • Complete Error checking for each Ri Call
    • Basic Error checking
      • Sanity checking
      • Per call checking
      • Parameterlist checking
  • RIB parser
    • Basic Syntax Parsing
    • Ri type determination
    • Token checking
    • Error checking
  • RIS
    • Args Parser
    • Shader loader
    • Param
    • Widget
    • Ri intergration - [ ] Call wrapping for Ri[call]Begin/Ri[call]End pairs
  • Call Fragments
  • Documentation/Examples
    • examples autogenerated from example tests
  • Siggarph 2003, Course 9 'Evolution of RIB' by Byron Bashforth
    • String Handles
    • Conditional RIB and State Variable Subsitution
    • inline Archives
    • Plug-in Ri Filters (partial)
    • Multipart RIB and Plug-in Instancers

###Information

RenderMan Interface Specification is Copyright © 2005-2016 Pixar. RenderMan © is a registered trademark of Pixar.

Documentation

Overview

rigo/presets.go

Index

Constants

View Source
const (
	Author RtToken = "RiGO;ver 0"
)

Variables

View Source
var (
	ErrInvalidContextHandle = fmt.Errorf("Invalid Context Handle")
	ErrContextAlreadyExists = fmt.Errorf("Context Already Exists")
	ErrNoActiveContext      = fmt.Errorf("No Active Context")
	ErrNotImplemented       = fmt.Errorf("Not Implemented")
	ErrPipeDone             = fmt.Errorf("Pipe Done")
	ErrEndOfLine            = fmt.Errorf("End of Line")
	ErrSkipPipe             = fmt.Errorf("Skip Rest of Pipe")
)

Functions

func CustomEntityPipeline

func CustomEntityPipeline(pipe *Pipe) *Ri

func DefaultPipeline

func DefaultPipeline(config *Configuration) (*Ri, *Pipe)

func EntityPipeline

func EntityPipeline() (*Ri, *Pipe)

func RI

func RI(ctx RiContexter) *Ri

Wrap the RI interface

func RIS

func RIS(ctx RisContexter) *Ris

Wrap the RIS interface

func StrictPipeline

func StrictPipeline() (*Ri, *Pipe)

Types

type Configuration

type Configuration struct {
	Entity             bool
	PrettyPrint        bool
	PrettyPrintSpacing string
}

type Context

type Context struct {
	HandleManagerer

	Info
	// contains filtered or unexported fields
}

func NewContext

func NewContext(pipe *Pipe, mgr HandleManagerer, config *Configuration) *Context

func (*Context) CloseRaw

func (ctx *Context) CloseRaw(id RtToken) error

CloseRaw

func (*Context) GetShader

func (ctx *Context) GetShader(sh RtShaderHandle) Shader

GetShader

func (*Context) OpenRaw

func (ctx *Context) OpenRaw(id RtToken) (ArchiveWriter, error)

OpenRaw

func (*Context) SetShader

func (ctx *Context) SetShader(sh RtShaderHandle, s Shader)

SetShader

func (*Context) Shader

func (ctx *Context) Shader(sh RtShaderHandle) ShaderWriter

Shader

func (*Context) Write

func (ctx *Context) Write(name RtName, args, params []Rter, values []Rter) error

Write

type FilterStringHandles

type FilterStringHandles struct{}

func (FilterStringHandles) Name

func (p FilterStringHandles) Name() string

func (*FilterStringHandles) Pipe

func (p *FilterStringHandles) Pipe(name RtName, args, params, values []Rter, info Info) *Result

func (*FilterStringHandles) ToRaw

func (p *FilterStringHandles) ToRaw() ArchiveWriter

type HandleManager

type HandleManager struct {
	// contains filtered or unexported fields
}

func NewHandleManager

func NewHandleManager(object ObjectHandler, light LightHandler, shader ShaderHandler) *HandleManager

func (*HandleManager) CheckLightHandle

func (mgr *HandleManager) CheckLightHandle(h RtLightHandle) error

func (*HandleManager) CheckObjectHandle

func (mgr *HandleManager) CheckObjectHandle(h RtObjectHandle) error

func (*HandleManager) CheckShaderHandle

func (mgr *HandleManager) CheckShaderHandle(h RtShaderHandle) error

func (*HandleManager) LightHandle

func (mgr *HandleManager) LightHandle() (RtLightHandle, error)

func (*HandleManager) ObjectHandle

func (mgr *HandleManager) ObjectHandle() (RtObjectHandle, error)

func (*HandleManager) ShaderHandle

func (mgr *HandleManager) ShaderHandle() (RtShaderHandle, error)

type HandleManagerer

type HandleManagerer interface {

	/* Light... */
	LightHandle() (RtLightHandle, error)
	CheckLightHandle(RtLightHandle) error

	/* Object... */
	ObjectHandle() (RtObjectHandle, error)
	CheckObjectHandle(RtObjectHandle) error

	/* Shader... */
	ShaderHandle() (RtShaderHandle, error)
	CheckShaderHandle(RtShaderHandle) error
}

HandleManager -- Collects all the handle management

type Info

type Info struct {
	Name               string
	Depth              int
	Lights             uint /* TODO: not required anymore */
	Objects            uint
	Entity             bool
	PrettyPrint        bool
	PrettyPrintSpacing string /* -- defaults to \t character */
}

func (Info) Copy

func (info Info) Copy() *Info

type LightHandlerCallback

type LightHandlerCallback func(RtName, RtLightHandle)

example of callbacks for light handle usage

type Pipe

type Pipe struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func DefaultFilePipe

func DefaultFilePipe() *Pipe

TODO: move defualt and null to presets/or delete

func NewEmptyPipe

func NewEmptyPipe() *Pipe

NewEmptyPipe -- does not include any issue fixes/used mainly for regression testing

func NewPipe

func NewPipe() *Pipe

func NullPipe

func NullPipe() *Pipe

func (*Pipe) Append

func (p *Pipe) Append(block Piper) *Pipe

func (*Pipe) Get

func (p *Pipe) Get(idx int) Piper

Get get a Piper object via index

func (*Pipe) GetByName

func (p *Pipe) GetByName(name string) Piper

GetByName get the first Piper object by name

func (*Pipe) Last

func (p *Pipe) Last() Piper

func (*Pipe) Len

func (p *Pipe) Len() int

Len get the length of the pipe

func (*Pipe) List

func (p *Pipe) List() []string

List -- get all the names of each pipe block

func (*Pipe) Run

func (p *Pipe) Run(name RtName, args, list []Rter, info Info) error

func (*Pipe) String

func (p *Pipe) String() string

func (*Pipe) ToRaw

func (p *Pipe) ToRaw() ArchiveWriter

type PipeHookHandleCallback

type PipeHookHandleCallback struct {
	LightHandler LightHandlerCallback
}

func (*PipeHookHandleCallback) Name

func (p *PipeHookHandleCallback) Name() string

func (*PipeHookHandleCallback) Pipe

func (p *PipeHookHandleCallback) Pipe(name RtName, args, params, values []Rter, info Info) *Result

func (*PipeHookHandleCallback) ToRaw

func (p *PipeHookHandleCallback) ToRaw() ArchiveWriter

type PipeIssue0001Fix

type PipeIssue0001Fix struct {
	Insession   bool /* have you seen a RiBegin */
	VersionSeen bool /* have you already seen a version name token*/
}

func (*PipeIssue0001Fix) Name

func (p *PipeIssue0001Fix) Name() string

func (*PipeIssue0001Fix) Pipe

func (p *PipeIssue0001Fix) Pipe(name RtName, args, params, values []Rter, info Info) *Result

func (*PipeIssue0001Fix) ToRaw

func (p *PipeIssue0001Fix) ToRaw() ArchiveWriter

type PipeTimer

type PipeTimer struct {
	// contains filtered or unexported fields
}

Time from Begin to End

func (PipeTimer) Name

func (p PipeTimer) Name() string

func (*PipeTimer) Pipe

func (p *PipeTimer) Pipe(name RtName, args, params, values []Rter, info Info) *Result

func (*PipeTimer) String

func (p *PipeTimer) String() string

func (*PipeTimer) ToRaw

func (p *PipeTimer) ToRaw() ArchiveWriter

func (*PipeTimer) Took

func (p *PipeTimer) Took() time.Duration

type PipeToDebugBuffer

type PipeToDebugBuffer struct {
	Buffer *bytes.Buffer
}

func (*PipeToDebugBuffer) Name

func (p *PipeToDebugBuffer) Name() string

func (*PipeToDebugBuffer) Pipe

func (p *PipeToDebugBuffer) Pipe(name RtName, args, params, values []Rter, info Info) *Result

func (*PipeToDebugBuffer) String

func (p *PipeToDebugBuffer) String() string

func (*PipeToDebugBuffer) ToRaw

func (p *PipeToDebugBuffer) ToRaw() ArchiveWriter

type PipeToFile

type PipeToFile struct {
	// contains filtered or unexported fields
}

Pipe RI output to file

func (PipeToFile) Name

func (p PipeToFile) Name() string

func (*PipeToFile) Pipe

func (p *PipeToFile) Pipe(name RtName, args, params, values []Rter, info Info) *Result

func (*PipeToFile) ToRaw

func (p *PipeToFile) ToRaw() ArchiveWriter

type PipeToPrettyPrint

type PipeToPrettyPrint struct {
	Depth int
}

func (*PipeToPrettyPrint) Name

func (p *PipeToPrettyPrint) Name() string

func (*PipeToPrettyPrint) Pipe

func (p *PipeToPrettyPrint) Pipe(name RtName, args, params, values []Rter, info Info) *Result

func (*PipeToPrettyPrint) ToRaw

func (p *PipeToPrettyPrint) ToRaw() ArchiveWriter

type PipeToStats

type PipeToStats struct {
	Stats map[RtName]int
}

Pipe RI output to gathered states

func (PipeToStats) Name

func (p PipeToStats) Name() string

func (*PipeToStats) Pipe

func (p *PipeToStats) Pipe(name RtName, args, params, values []Rter, info Info) *Result

func (*PipeToStats) String

func (p *PipeToStats) String() string

func (*PipeToStats) ToRaw

func (p *PipeToStats) ToRaw() ArchiveWriter

type Piper

type Piper interface {
	/* name, []args,[]params,[]values,info */
	Pipe(RtName, []Rter, []Rter, []Rter, Info) *Result
	Name() string
	ToRaw() ArchiveWriter
}

type Result

type Result struct {
	Name   RtName
	Args   []Rter
	Params []Rter
	Values []Rter
	Info   *Info
	Err    error
}

func Done

func Done() *Result

func EndOfLine

func EndOfLine() *Result

func Errored

func Errored(message RtString) *Result

func InError

func InError(err error) *Result

func Next

func Next(name RtName, args, params, values []Rter, info Info) *Result

func Skip

func Skip() *Result

Directories

Path Synopsis
examples
bunny
rigo/examples/bunny/bunny.go * render the Standford Bunny just using RiGO
rigo/examples/bunny/bunny.go * render the Standford Bunny just using RiGO
regressions
ri
rigo/definitions.go rigo/ri/handles.go rigo/ri/handles.go rigo/ri/handles.go rigo/ri/handles.go
rigo/definitions.go rigo/ri/handles.go rigo/ri/handles.go rigo/ri/handles.go rigo/ri/handles.go
headers
RtToken generator
RtToken generator
rib
rigo/ri/rib/parser.go
rigo/ri/rib/parser.go
xml args parser
xml args parser

Jump to

Keyboard shortcuts

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