public override void _Ready() { int i = 0; this.Multimesh.InstanceCount = 0; if (Global.IsLoaded) { this.Multimesh.InstanceCount = Global.LoadedMeat.Count; foreach (Godot.Collections.Dictionary m in Global.LoadedMeat) { Meat newMeat = new Meat(); newMeat.meatSpatial = (Spatial) new Spatial(); newMeat.meatSpatial.Translation = new Vector3((float)m["MeatTranslationX"], (float)m["MeatTranslationY"], (float)m["MeatTranslationZ"]); newMeat.meatSpatial.Scale = new Vector3((float)m["MeatScaleX"], (float)m["MeatScaleY"], (float)m["MeatScaleZ"]); newMeat.timeOnGround = (float)m["TimeOnGround"]; newMeat.EatersCount = (int)((float)m["EatersCount"]); newMeat.Collider = (CreatureCollider) new CreatureCollider(); newMeat.Collider.Translation = new Vector3((float)m["ColliderTranslationX"], (float)m["ColliderTranslationY"], (float)m["ColliderTranslationZ"]); newMeat.Collider.MyMeat = newMeat; newMeat.Collider.MyCreatureAlive = false; AddChild(newMeat.Collider); newMeat.decay = (int)((float)m["Decay"]); newMeat.meatGone = (bool)m["MeatGone"]; MeatArray.Add(newMeat); Multimesh.SetInstanceTransform(i, newMeat.meatSpatial.Transform); i++; } MeatBiomassArray = DataCollector.ConvertToFloatArray(Global.LoadedMeatBiomass); } else { MeatBiomassArray.Add(0.0f); } }
public virtual void Draw() { if (Multimesh != null) { int visibleParticles = 0; foreach (Particle particle in particles) { if (particle.alive) { Transform t = particle.transform; if (!local) { t = GlobalTransform.AffineInverse() * t; } Multimesh.SetInstanceTransform(visibleParticles, t); Multimesh.SetInstanceColor(visibleParticles, particle.color); visibleParticles++; } } Multimesh.VisibleInstanceCount = visibleParticles; } }
public override void _Ready() { // Init vars random = new RandomNumberGenerator(); Color grass = Color.Color8(100, 200, 25); Color water = Color.Color8(0, 130, 200); // Set meshes count Multimesh.InstanceCount = Width * Length * Height; // Create map Mesh mesh = Multimesh.Mesh; Vector3 meshSize = mesh.GetAabb().Size; int instance = 0; Console.WriteLine(meshSize); for (int h = 0; h < Height; h++) { for (int l = 0; l < Length; l++) { for (int w = 0; w < Width; w++) { Color currentColor; if (h <= Height - 2) { currentColor = grass; } else { int color = random.RandiRange(0, 1); currentColor = color == 0 ? grass : water; } Multimesh.SetInstanceColor(instance, currentColor); Transform position = Transform.Identity.Translated(new Vector3(w * meshSize.x, h * meshSize.y, l * meshSize.z)); Multimesh.SetInstanceTransform(instance, position); Console.WriteLine(position.origin); instance++; } } } }
public override void _Process(float delta) { for (int i = 0; i < MeatArray.Count; i++) { if (!MeatToRemove.Contains(i)) { temp.Add(MeatArray[i]); } } MeatArray.Clear(); for (int i = 0; i < temp.Count; i++) { MeatArray.Add(temp[i]); } for (int i = 0; i < MeatToAdd.Count; i++) { MeatArray.Add(MeatToAdd[i]); } MeatToRemove.Clear(); MeatToAdd.Clear(); temp.Clear(); Multimesh.InstanceCount = MeatArray.Count; for (int i = 0; i < MeatArray.Count; i++) { MeatArray[i].timeOnGround += TimeMultiplier * delta; if (MeatArray[i].timeOnGround >= MaxTimeOnGround) { MeatArray[i].decay = 1; } if (MeatArray[i].EatersCount > 0 || MeatArray[i].decay > 0) { Vector3 eatRate = (Vector3) new Vector3(1, 1, 1); eatRate *= (MeatArray[i].EatersCount + MeatArray[i].decay) * 0.5f * TimeMultiplier * delta; MeatArray[i].meatSpatial.Scale -= eatRate; if (MeatArray[i].meatSpatial.Scale.x < 0.05f) { MeatArray[i].meatGone = true; MeatArray[i].Collider.QueueFree(); AddChild(MeatArray[i].meatSpatial); MeatArray[i].meatSpatial.QueueFree(); MeatToRemove.Add(i); } } Multimesh.SetInstanceTransform(i, MeatArray[i].meatSpatial.Transform); } }
private void GenerateTerrain() { Multimesh.TransformFormat = MultiMesh.TransformFormatEnum.Transform3d; Multimesh.ColorFormat = MultiMesh.ColorFormatEnum.Color8bit; Multimesh.CustomDataFormat = MultiMesh.CustomDataFormatEnum.Data8bit; Multimesh.VisibleInstanceCount = Multimesh.InstanceCount; var length = (int)Mathf.Sqrt(Multimesh.VisibleInstanceCount); length = (int)(length * 0.5f); int count = 0; for (int i = -length; i < length; i++) { for (int j = -length; j < length; j++) { var translation = new Vector3(.5f + i, 0, .5f + j); Multimesh.SetInstanceTransform(count, new Transform(Basis.Identity, translation)); // add shader info UnselectInstance(count); //add selection area this.AddChild(new TerrainArea(count, translation)); count++; } } // generate the static body var body = new StaticBody(); var collider = new CollisionShape(); var box = new BoxShape(); collider.Shape = box; box.Extents = new Vector3(length + 0.005f, 0.2f, length + 0.005f); body.CollisionLayer = 2; //floor -> layer 1 -> tag = 2¹; body.CollisionMask = 0; //player > layer 1 -> tag = 2⁰; body.AddChild(collider); AddChild(body); collider.Translation = new Vector3(0, -0.19f, 0); }