public Entity FromSceneryInstance(ScenarioTag.SceneryInstance scen) { var entity = SceneryFactory.FromTag(this.Map, this.Map.Scenario, scen); scen.GameObject = entity; return(entity); }
public static Scenery FromTag(H2vMap map, ScenarioTag scenario, ScenarioTag.SceneryInstance instance) { var scenery = new Scenery(); scenery.FriendlyName = "Scenery_" + instance.SceneryDefinitionIndex; var id = scenario.SceneryDefinitions[instance.SceneryDefinitionIndex].Scenery; var tag = map.GetTag(id); scenery.FriendlyName = tag.Name; var meshes = MeshFactory.GetRenderModel(map, tag.Model); var transparentMeshes = new List <Mesh <BitmapTag> >(meshes.Length); var renderModelMeshes = new List <Mesh <BitmapTag> >(meshes.Length); foreach (var mesh in meshes) { var mat = mesh.Material; if (mat.AlphaMap == null) { renderModelMeshes.Add(mesh); } else { transparentMeshes.Add(mesh); } } var components = new List <Component>(); components.Add(new RenderModelComponent(scenery, new Model <BitmapTag> { Note = $"[{tag.Id}] {tag.Name}", Meshes = renderModelMeshes.ToArray(), Flags = ModelFlags.Diffuse | ModelFlags.CastsShadows | ModelFlags.ReceivesShadows })); foreach (var transparentMesh in transparentMeshes) { components.Add(new RenderModelComponent(scenery, new Model <BitmapTag> { Note = $"[{tag.Id}] {tag.Name}", Meshes = new[] { transparentMesh }, Flags = ModelFlags.IsTransparent })); } var orientation = QuaternionExtensions.FromH2vOrientation(instance.Orientation); var xform = new TransformComponent(scenery, instance.Position, orientation); var body = PhysicsComponentFactory.CreateStaticRigidBody(scenery, xform, map, tag.Model); if (body != null) { components.Add(body); components.Add(new RenderModelComponent(scenery, new Model <BitmapTag> { Note = $"scenery//{scenery.FriendlyName}-collision", Meshes = MeshFactory.GetRenderModel(body.Collider, new Vector4(0.9f, 0.5f, .24f, 1f)), Flags = ModelFlags.Wireframe | ModelFlags.IsStatic, RenderLayer = RenderLayers.Collision })); } scenery.SetComponents(xform, components.ToArray()); return(scenery); }