/// <summary> /// Create a render component. All rendering info for an entity comes from here. /// </summary> /// <param name="parent">Entity this component will be attached to</param> public RenderComponent(BaseEntity parent, RenderComponentDefinition compDef) : base(parent) { ActivateComponent(); if (compDef.PrimitiveType != GeometricPrimitiveType.Invalid) { LoadModelFromPrimitive(compDef.PrimitiveType, compDef.Height, compDef.Width, compDef.Depth, compDef.Diameter); } else if (compDef.ModelPath.Length > 0) { LoadModel(compDef.ModelPath); } else { throw new Exception("A RenderComponentDefinition must contain either a valid primitive type, or a path to a model asset file"); } if (compDef.MaterialPath.Length > 0) { LoadMaterial(compDef.MaterialPath); } else { throw new Exception("A RenderComponentDefintion must contain a valid material path"); } this.renderOrder = compDef.RenderOrder; this.canCreateShadows = compDef.CanCreateShadows; this.canReceiveShadows = compDef.CanReceiveShadows; this.ModelColor = new Color(compDef.MeshColor); this.rendersAsSky = compDef.RendersAsSky; this.Opacity = compDef.Opacity; }
public static BaseComponent LoadFromDefinition(ContentManager content, string definitionPath, BaseEntity parent) { RenderComponentDefinition compDef = content.Load <RenderComponentDefinition>(definitionPath); RenderComponent newComponent = new RenderComponent(parent, compDef); return(newComponent); }