private void CreateShape(Microbe parent) { float pilusSize = 4.6f; // Scale the size down for bacteria if (organelle.ParentMicrobe.Species.IsBacteria) { pilusSize *= 0.5f; } // TODO: Godot doesn't have Cone shape. // https://github.com/godotengine/godot-proposals/issues/610 // So this uses a cylinder for now // Create the shape var shape = new CylinderShape(); shape.Radius = pilusSize / 10.0f; shape.Height = pilusSize; var ownerId = parent.CreateShapeOwner(shape); parent.ShapeOwnerAddShape(ownerId, shape); parent.AddPilus(ownerId); addedChildShapes.Add(ownerId); }
/// <summary> /// Called by a microbe when this organelle has been added to it /// </summary> public void OnAddedToMicrobe(Microbe microbe) { if (Definition == null) { throw new Exception("PlacedOrganelle has no definition set"); } if (ParentMicrobe != null) { throw new InvalidOperationException("PlacedOrganelle is already in a microbe"); } // Store parameters ParentMicrobe = microbe; // Grab the species colour for us Colour = microbe.Species.Colour; ParentMicrobe.OrganelleParent.AddChild(this); // Graphical display if (Definition.LoadedScene != null) { SetupOrganelleGraphics(); } float hexSize = Constants.DEFAULT_HEX_SIZE; // Scale the physics hex size down for bacteria if (microbe.Species.IsBacteria) { hexSize *= 0.5f; } // Physics ParentMicrobe.Mass += Definition.Mass; // Add hex collision shapes foreach (Hex hex in Definition.GetRotatedHexes(Orientation)) { var shape = new SphereShape(); shape.Radius = hexSize * 2.0f; var ownerId = ParentMicrobe.CreateShapeOwner(shape); // This is needed to actually add the shape ParentMicrobe.ShapeOwnerAddShape(ownerId, shape); // The shape is in our parent so the final position is our // offset plus the hex offset Vector3 shapePosition = Hex.AxialToCartesian(hex) + Translation; // Scale for bacteria physics. if (microbe.Species.IsBacteria) { shapePosition *= 0.5f; } var transform = new Transform(Quat.Identity, shapePosition); ParentMicrobe.ShapeOwnerSetTransform(ownerId, transform); shapes.Add(ownerId); } // Components Components = new List <IOrganelleComponent>(); foreach (var factory in Definition.ComponentFactories) { var component = factory.Create(); if (component == null) { throw new Exception("PlacedOrganelle component factory returned null"); } component.OnAttachToCell(this); Components.Add(component); } ResetGrowth(); }
/// <summary> /// Called by a microbe when this organelle has been added to it /// </summary> public void OnAddedToMicrobe(Microbe microbe) { if (Definition == null) { throw new Exception("PlacedOrganelle has no definition set"); } if (ParentMicrobe != null) { throw new InvalidOperationException("PlacedOrganelle is already in a microbe"); } // Store parameters ParentMicrobe = microbe; // Grab the species colour for us Colour = microbe.Species.Colour; ParentMicrobe.OrganelleParent.AddChild(this); // Graphical display if (Definition.LoadedScene != null) { // There is an intermediate node so that the organelle scene root rotation and scale work OrganelleGraphics = new Spatial(); var organelleSceneInstance = (Spatial)Definition.LoadedScene.Instance(); AddChild(OrganelleGraphics); OrganelleGraphics.Scale = new Vector3(Constants.DEFAULT_HEX_SIZE, Constants.DEFAULT_HEX_SIZE, Constants.DEFAULT_HEX_SIZE); var transform = new Transform(MathUtils.CreateRotationForOrganelle(Orientation), Definition.CalculateModelOffset()); OrganelleGraphics.Transform = transform; // Store the material of the organelle to be updated GeometryInstance geometry; // Fetch the actual model from the scene to get at the material we set the tint on if (string.IsNullOrEmpty(Definition.DisplaySceneModelPath)) { geometry = (GeometryInstance)organelleSceneInstance; } else { geometry = organelleSceneInstance.GetNode <GeometryInstance>(Definition.DisplaySceneModelPath); } // Store animation player for later use if (!string.IsNullOrEmpty(Definition.DisplaySceneAnimation)) { OrganelleAnimation = organelleSceneInstance.GetNode <AnimationPlayer>(Definition.DisplaySceneAnimation); } organelleMaterial = (ShaderMaterial)geometry.MaterialOverride; OrganelleGraphics.AddChild(organelleSceneInstance); } // Position relative to origin of cell RotateY(Orientation * 60); Translation = Hex.AxialToCartesian(Position); float hexSize = Constants.DEFAULT_HEX_SIZE; // Scale the physics hex size down for bacteria if (microbe.Species.IsBacteria) { hexSize *= 0.5f; } // Physics ParentMicrobe.Mass += Definition.Mass; // Add hex collision shapes foreach (Hex hex in Definition.GetRotatedHexes(Orientation)) { var shape = new SphereShape(); shape.Radius = hexSize * 2.0f; var ownerId = ParentMicrobe.CreateShapeOwner(shape); // This is needed to actually add the shape ParentMicrobe.ShapeOwnerAddShape(ownerId, shape); // The shape is in our parent so the final position is our // offset plus the hex offset Vector3 shapePosition = Hex.AxialToCartesian(hex) + Translation; // Scale for bacteria physics. if (microbe.Species.IsBacteria) { shapePosition *= 0.5f; } var transform = new Transform(Quat.Identity, shapePosition); ParentMicrobe.ShapeOwnerSetTransform(ownerId, transform); shapes.Add(ownerId); } // Components Components = new List <IOrganelleComponent>(); foreach (var factory in Definition.ComponentFactories) { var component = factory.Create(); if (component == null) { throw new Exception("PlacedOrganelle component factory returned null"); } component.OnAttachToCell(this); Components.Add(component); } ResetGrowth(); }