コード例 #1
0
ファイル: examples_test.go プロジェクト: mae-global/rigo
func Test_ExampleD14(t *testing.T) {

	Convey("Example D1.4", t, func() {

		sgroup := RtToken("shadinggroup")
		frames := 2
		cuser, err := user.Current()
		So(err, ShouldBeNil)

		ri, pipe := DefaultPipeline(&Configuration{PrettyPrint: true})
		ri.Begin("output/exampleD14.rib")
		ri.ArchiveRecord("structure", "Scene Bouncing Ball")
		ri.ArchiveRecord("structure", "Creator %s", Author)
		ri.ArchiveRecord("structure", "CreationDate %s", time.Now())
		ri.ArchiveRecord("structure", "For %s", cuser.Username)
		ri.ArchiveRecord("structure", "Frames %d", frames)
		ri.ArchiveRecord("structure", "Shaders PIXARmarble, PIXARwood, MyUserShader")
		ri.ArchiveRecord("structure", "CapabilitiesNeeded ShadingLanguage Displacements")
		ri.Declare("d", "uniform point")
		ri.Declare("squish", "uniform float")
		ri.Option("limits", RtToken("bucketsize"), RtIntArray{6, 6})
		ri.Option("limits", RtToken("gridsize"), RtIntArray{18})
		ri.Format(1024, 768, 1)
		ri.Projection(PERSPECTIVE)
		ri.Clipping(10, 1000.0)

		ri.FrameBegin(1)
		ri.ArchiveRecord("structure", "Shaders PIXARmarble, PIXARwood")
		ri.ArchiveRecord("structure", "CameraOrientation %.1f %.1f %.1f %.1f %.1f %.1f", 10., 10., 10., 0., 0., 0.)
		ri.Transform(RtMatrix{.707107, -.408248, 0.57735, 0, 0, .816497, -.57735, 0, -.707107, -.408248, -.57735, 0, 0, 0, 17.3205, 1})
		ri.WorldBegin()
		ri.AttributeBegin()
		ri.Attribute("identifier", RtToken("name"), RtString("myball"))
		ri.Displacement("MyUserShader", RtToken("squish"), RtInt(5))
		ri.AttributeBegin()
		ri.Attribute("identifier", sgroup, RtStringArray{"tophalf"})
		ri.Surface("plastic")
		ri.Sphere(.5, -.5, 0, 360)
		ri.AttributeEnd()
		ri.AttributeBegin()
		ri.Attribute("identifier", sgroup, RtStringArray{"bothalf"})
		ri.Surface("PIXARmarble")
		ri.Sphere(.5, 0, .5, 360)
		ri.AttributeEnd()
		ri.AttributeEnd()
		ri.AttributeBegin()
		ri.Attribute("identifier", RtToken("name"), RtStringArray{"floor"})
		ri.Surface("PIXARwood", RtToken("roughness"), RtFloatArray{.3}, RtToken("d"), RtIntArray{1})
		ri.Comment("geometry for floor")
		ri.Polygon(4, RtToken("P"), RtFloatArray{-100, 0, -100, -100, 0, 100, 100, 0, 100, 10, 0, -100})
		ri.AttributeEnd()
		ri.WorldEnd()
		ri.FrameEnd()

		ri.FrameBegin(2)
		ri.ArchiveRecord("structure", "Shaders PIXARwood, PIXARmarbles")
		ri.ArchiveRecord("structure", "CameraOrientation %.1f %.1f %.1f %.1f %.1f %.1f", 10., 20., 10., 0., 0., 0.)
		ri.Transform(RtMatrix{.707107, -.57735, -.408248, 0, 0, .57735, -.815447, 0, -.707107, -.57735, -.408248, 0, 0, 0, 24.4949, 1})
		ri.WorldBegin()
		ri.AttributeBegin()
		ri.Attribute("identifier", RtToken("name"), RtStringArray{"myball"})
		ri.AttributeBegin()
		ri.Attribute("identifier", sgroup, RtStringArray{"tophalf"})
		ri.Surface("PIXARmarble")
		ri.ShadingRate(.1)
		ri.Sphere(.5, 0, .5, 360)
		ri.AttributeEnd()
		ri.AttributeBegin()
		ri.Attribute("identifier", sgroup, RtStringArray{"bothalf"})
		ri.Surface("plastic")
		ri.Sphere(.5, -.5, 0, 360)
		ri.AttributeEnd()
		ri.AttributeEnd()
		ri.AttributeBegin()
		ri.Attribute("identifier", RtToken("name"), RtStringArray{"floor"})
		ri.Surface("PIXARwood", RtToken("roughness"), RtFloatArray{.3}, RtToken("d"), RtIntArray{1})
		ri.Comment("geometry for floor")
		ri.Polygon(4, RtToken("P"), RtFloatArray{-100, 0, -100, -100, 0, 100, 100, 0, 100, 10, 0, -100})
		ri.AttributeEnd()
		ri.WorldEnd()
		ri.FrameEnd()

		So(ri.End(), ShouldBeNil)

		/* output gathered stats */
		p := pipe.GetByName(PipeToStats{}.Name())
		So(p, ShouldNotBeNil)
		s, ok := p.(*PipeToStats)
		So(s, ShouldNotBeNil)
		So(ok, ShouldBeTrue)

		p = pipe.GetByName(PipeTimer{}.Name())
		So(p, ShouldNotBeNil)
		t, ok := p.(*PipeTimer)
		So(t, ShouldNotBeNil)
		So(ok, ShouldBeTrue)

		fmt.Printf("%s%s", s, t)
	})
}
コード例 #2
0
ファイル: examples_test.go プロジェクト: mae-global/rigo
func Test_ExampleD21(t *testing.T) {

	Convey("Example D.2.1 RIB Entity", t, func() {

		ri, pipe := EntityPipeline()
		ri.Begin("output/exampleD21.rib")
		ri.AttributeBegin("begin unit cube")
		ri.Attribute("identifier", RtToken("name"), RtToken("unitcube"))
		ri.Bound(RtBound{-.5, .5, -.5, .5, -.5, .5})
		ri.TransformBegin()

		ri.Comment("far face")
		ri.Polygon(4, RtToken("P"), RtFloatArray{.5, .5, .5, -.5, .5, .5, -.5, -.5, .5, .5, -.5, .5})
		ri.Rotate(90, 0, 1, 0)

		ri.Comment("right face")
		ri.Polygon(4, RtToken("P"), RtFloatArray{.5, .5, .5, -.5, .5, .5, -.5, -.5, .5, .5, -.5, .5})
		ri.Rotate(90, 0, 1, 0)

		ri.Comment("near face")
		ri.Polygon(4, RtToken("P"), RtFloatArray{.5, .5, .5, -.5, .5, .5, -.5, -.5, .5, .5, -.5, .5})
		ri.Rotate(90, 0, 1, 0)

		ri.Comment("left face")
		ri.Polygon(4, RtToken("P"), RtFloatArray{.5, .5, .5, -.5, .5, .5, -.5, -.5, .5, .5, -.5, .5})

		ri.TransformEnd()
		ri.TransformBegin()

		ri.Comment("bottom face")
		ri.Rotate(90, 1, 0, 0)
		ri.Polygon(4, RtToken("P"), RtFloatArray{.5, .5, .5, -.5, .5, .5, -.5, -.5, .5, .5, -.5, .5})

		ri.TransformEnd()
		ri.TransformBegin()

		ri.Comment("top face")
		ri.Rotate(-90, 1, 0, 0)
		ri.Polygon(4, RtToken("P"), RtFloatArray{.5, .5, .5, -.5, .5, .5, -.5, -.5, .5, .5, -.5, .5})

		ri.TransformEnd()
		ri.AttributeEnd("end unit cube")

		So(ri.End(), ShouldBeNil)

		/* output gathered stats */
		p := pipe.GetByName(PipeToStats{}.Name())
		So(p, ShouldNotBeNil)
		s, ok := p.(*PipeToStats)
		So(s, ShouldNotBeNil)
		So(ok, ShouldBeTrue)

		p = pipe.GetByName(PipeTimer{}.Name())
		So(p, ShouldNotBeNil)
		t, ok := p.(*PipeTimer)
		So(t, ShouldNotBeNil)
		So(ok, ShouldBeTrue)

		fmt.Printf("%s%s", s, t)

	})
}