Просмотр исходного кода

improved IGraphic and GraphicMaterial API

Daniel Salvadori 7 лет назад
Родитель
Сommit
6eb8664ae8

+ 1 - 1
experimental/physics/narrowphase.go

@@ -299,7 +299,7 @@ func (n *Narrowphase) SphereConvex(bodyA, bodyB *object.Body, sphereA *shape.Sph
 
 	// First check if any vertex of the convex hull is inside the sphere
 	done := false
-	convexB.GetGeometry().ReadVertices(func(vertex math32.Vector3) bool {
+	convexB.Geometry.ReadVertices(func(vertex math32.Vector3) bool {
 		worldVertex := vertex.ApplyQuaternion(quatA).Add(posB)
 		sphereToCorner := math32.NewVec3().SubVectors(worldVertex, posA)
 		if sphereToCorner.LengthSq() < sphereRadius * sphereRadius {

+ 2 - 2
experimental/physics/shape/convexhull.go

@@ -43,7 +43,7 @@ func NewConvexHull(geom *geometry.Geometry) *ConvexHull {
 // Compute and store face normals and unique edges
 func (ch *ConvexHull) computeFaceNormalsAndUniqueEdges() {
 
-	ch.GetGeometry().ReadFaces(func(vA, vB, vC math32.Vector3) bool {
+	ch.Geometry.ReadFaces(func(vA, vB, vC math32.Vector3) bool {
 
 		// Store face vertices
 		var face [3]math32.Vector3
@@ -235,7 +235,7 @@ func (ch *ConvexHull) ProjectOntoWorldAxis(worldAxis, pos *math32.Vector3, quat
 	localAxis := worldAxis.Clone().ApplyQuaternion(quatConj)
 
 	// Project onto the local axis
-	max, min := ch.GetGeometry().ProjectOntoAxis(localAxis)
+	max, min := ch.Geometry.ProjectOntoAxis(localAxis)
 
 	// Offset to obtain values relative to world origin
 	localOrigin := math32.NewVec3().Sub(pos).ApplyQuaternion(quatConj)

+ 15 - 7
graphic/graphic.go

@@ -44,10 +44,11 @@ type IGraphic interface {
 	core.INode
 	GetGraphic() *Graphic
 	GetGeometry() *geometry.Geometry
-	Renderable() bool
+	IGeometry() geometry.IGeometry
 	SetRenderable(bool)
-	Cullable() bool
+	Renderable() bool
 	SetCullable(bool)
+	Cullable() bool
 	RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo)
 }
 
@@ -84,7 +85,14 @@ func (gr *Graphic) GetGraphic() *Graphic {
 // a pointer to the geometry associated with this graphic.
 func (gr *Graphic) GetGeometry() *geometry.Geometry {
 
-	return gr.igeom.GetGeometry() // TODO return igeom
+	return gr.igeom.GetGeometry()
+}
+
+// IGeometry satisfies the IGraphic interface and returns
+// a pointer to the IGeometry associated with this graphic.
+func (gr *Graphic) IGeometry() geometry.IGeometry {
+
+	return gr.igeom
 }
 
 // Dispose overrides the embedded Node Dispose method.
@@ -205,14 +213,14 @@ func (gr *Graphic) ModelViewProjectionMatrix() *math32.Matrix4 {
 	return &gr.mvpm
 }
 
-// GetMaterial returns the material associated with the GraphicMaterial.
-func (grmat *GraphicMaterial) GetMaterial() material.IMaterial {
+// IMaterial returns the material associated with the GraphicMaterial.
+func (grmat *GraphicMaterial) IMaterial() material.IMaterial {
 
 	return grmat.imat
 }
 
-// GetGraphic returns the graphic associated with the GraphicMaterial.
-func (grmat *GraphicMaterial) GetGraphic() IGraphic {
+// IGraphic returns the graphic associated with the GraphicMaterial.
+func (grmat *GraphicMaterial) IGraphic() IGraphic {
 
 	return grmat.igraphic
 }

+ 6 - 6
renderer/renderer.go

@@ -284,7 +284,7 @@ func (r *Renderer) renderScene(iscene core.INode, icam camera.ICamera) error {
 		// Append all graphic materials of this graphic to list of graphic materials to be rendered
 		materials := gr.Materials()
 		for i := 0; i < len(materials); i++ {
-			if materials[i].GetMaterial().GetMaterial().Transparent() {
+			if materials[i].IMaterial().GetMaterial().Transparent() {
 				r.grmatsTransp = append(r.grmatsTransp, &materials[i])
 			} else {
 				r.grmatsOpaque = append(r.grmatsOpaque, &materials[i])
@@ -300,8 +300,8 @@ func (r *Renderer) renderScene(iscene core.INode, icam camera.ICamera) error {
 		var zSortGraphicMaterials func(grmats []*graphic.GraphicMaterial, backToFront bool)
 		zSortGraphicMaterials = func(grmats []*graphic.GraphicMaterial, backToFront bool) {
 			sort.Slice(grmats, func(i, j int) bool {
-				gr1 := grmats[i].GetGraphic().GetGraphic()
-				gr2 := grmats[j].GetGraphic().GetGraphic()
+				gr1 := grmats[i].IGraphic().GetGraphic()
+				gr2 := grmats[j].IGraphic().GetGraphic()
 
 				// Check for user-supplied render order
 				rO1 := gr1.RenderOrder()
@@ -378,8 +378,8 @@ func (r *Renderer) renderScene(iscene core.INode, icam camera.ICamera) error {
 	renderGraphicMaterials = func(grmats []*graphic.GraphicMaterial) {
 		// For each *GraphicMaterial
 		for _, grmat := range grmats {
-			mat := grmat.GetMaterial().GetMaterial()
-			geom := grmat.GetGraphic().GetGeometry()
+			mat := grmat.IMaterial().GetMaterial()
+			geom := grmat.IGraphic().GetGeometry()
 
 			// Add defines from material and geometry
 			r.specs.Defines = *gls.NewShaderDefines()
@@ -539,7 +539,7 @@ func (r *Renderer) renderPanel(ipan gui.IPanel) error {
 	if pan.Renderable() {
 		// Sets shader program for the panel's material
 		grmat := pan.GetGraphic().Materials()[0]
-		mat := grmat.GetMaterial().GetMaterial()
+		mat := grmat.IMaterial().GetMaterial()
 		r.specs.Name = mat.Shader()
 		r.specs.ShaderUnique = mat.ShaderUnique()
 		_, err := r.shaman.SetProgram(&r.specs)