func addCrates(scene *ng.Scene, num int) { var f float64 oldLen := len(crateIDs) nuLen := oldLen + 3 if nuLen > cap(crateIDs) { nu := make([]int, len(crateIDs), len(crateIDs)*2) copy(nu, crateIDs) crateIDs = nu } for i := 0; i < num; i++ { tmpNode = apputil.AddNode(scene, 0, meshCubeID, -1, -1) crateIDs = append(crateIDs, tmpNode.ID) f = float64(oldLen + i) tmpNode.Transform.SetPos((f+3)*-2, (f+1)*2, (f+2)*3) switch i { case 0: tmpNode.Render.MatID = apputil.LibIDs.Mat["mix"] case 1: apputil.AddNode(scene, tmpNode.ID, meshPyrID, apputil.LibIDs.Mat["cat"], -1).Transform.Pos.Y = 2.125 case 2: tmpNode.Render.ModelID = modelCubeCatID } } scene.ApplyNodeTransforms(0) }
func removeCrates(scene *ng.Scene, num int) { if len(crateIDs) >= num { for i := len(crateIDs) - num; i < len(crateIDs); i++ { scene.RemoveNode(crateIDs[i]) } crateIDs = crateIDs[:len(crateIDs)-num] } }
func AddSkyMesh(scene *ng.Scene, meshID int) { cubeMapID := ng.Core.Libs.Images.TexCube.AddNew() cubeMap := &ng.Core.Libs.Images.TexCube[cubeMapID] LibIDs.ImgCube["sky"] = cubeMapID cubeMap.InitFrom[0].RefUrl = "tex/sky/east.png" // positive X cubeMap.InitFrom[1].RefUrl = "tex/sky/west.png" // negative X cubeMap.InitFrom[2].RefUrl = "tex/sky/up.png" // positive Y cubeMap.InitFrom[3].RefUrl = "tex/sky/down.png" // negative Y cubeMap.InitFrom[4].RefUrl = "tex/sky/north.png" // positive Z cubeMap.InitFrom[5].RefUrl = "tex/sky/south.png" // negative Z fxID := ng.Core.Libs.Effects.AddNew() LibIDs.Fx["sky"] = fxID fx := &ng.Core.Libs.Effects[fxID] fx.EnableTexCube(0).Tex.ImageID = cubeMap.ID fx.EnableCoords(0) fx.DisableCoords(0) fx.UpdateRoutine() matID := ng.Core.Libs.Materials.AddNew() ng.Core.Libs.Materials[matID].DefaultEffectID = LibIDs.Fx["sky"] LibIDs.Mat["sky"] = matID scene.SetNodeMeshID(0, meshID) scene.Root().Render.MatID = matID }
func AddNode(scene *ng.Scene, parentNodeID, meshID, matID, modelID int) (node *ng.SceneNode) { nodeID := scene.AddNewChildNode(parentNodeID, meshID) node = scene.Node(nodeID) node.Render.MatID, node.Render.ModelID = matID, modelID return }