/// <summary> /// Convert from idTech5 map /// </summary> /// <param name="_Map"></param> public Scene( idTech5Map.Map _Map ) { // Create nodes m_RootNode = new Node( this, _Map ); // Create materials foreach ( idTech5Map.Material M in idTech5Map.Material.ms_Materials ) { m_Materials.Add( new Material( M ) ); } }
// public Node( Scene _Owner, idTech5Map.Map _Map ) { m_Owner = _Owner; m_Owner.m_Nodes.Add( this ); List< Node > Children = new List< Node >(); foreach ( idTech5Map.Map.Entity E in _Map.m_Entities ) { switch ( E.m_Type ) { case idTech5Map.Map.Entity.TYPE.MODEL: { Node Child = new Mesh( _Owner, E ); Child.m_Type = TYPE.MESH; Children.Add( Child ); break; } case idTech5Map.Map.Entity.TYPE.LIGHT: { Node Child = new Light( _Owner, E ); Child.m_Type = TYPE.LIGHT; Children.Add( Child ); break; } case idTech5Map.Map.Entity.TYPE.PLAYER_START: { Node Child = new Camera( _Owner, E ); Child.m_Type = TYPE.CAMERA; Children.Add( Child ); break; } case idTech5Map.Map.Entity.TYPE.PROBE: { Node Child = new Node( _Owner, E ); Child.m_Type = TYPE.PROBE; Children.Add( Child ); break; } case idTech5Map.Map.Entity.TYPE.UNKNOWN: case idTech5Map.Map.Entity.TYPE.REF_MAP: // Don't care... break; } } m_Children = Children.ToArray(); }
public Primitive( Mesh _Owner, idTech5Map.Model.Surface _Surface ) { m_Owner = _Owner; m_MaterialID = (ushort) _Surface.m_Material.m_MaterialIndex; int FacesCount = _Surface.m_Indices.Length / 3; m_Faces = new Face[FacesCount]; m_Vertices = new Vertex[_Surface.m_Vertices.Length]; m_BBoxMin = _Surface.m_BoundsMin; m_BBoxMax = _Surface.m_BoundsMax; // Build faces int i = 0; for ( int FaceIndex=0; FaceIndex < FacesCount; FaceIndex++ ) { m_Faces[FaceIndex].V0 = _Surface.m_Indices[i++]; m_Faces[FaceIndex].V2 = _Surface.m_Indices[i++]; // Here we reverse faces' orientation m_Faces[FaceIndex].V1 = _Surface.m_Indices[i++]; } // Build vertices for ( int VertexIndex=0; VertexIndex < m_Vertices.Length; VertexIndex++ ) { idTech5Map.Model.Surface.Vertex V = _Surface.m_Vertices[VertexIndex]; m_Vertices[VertexIndex].P = V.Position; m_Vertices[VertexIndex].N = V.Normal; m_Vertices[VertexIndex].G = V.Tangent; m_Vertices[VertexIndex].B = V.BiTangent; m_Vertices[VertexIndex].T = V.UVs[0]; } }
public Mesh( Scene _Owner, idTech5Map.Map.Entity _Entity ) : base(_Owner, _Entity) { // BUild primitives and local space BBox m_Primitives = new Primitive[_Entity.m_Model.m_Surfaces.Length]; m_BBoxMin_Local = float.MaxValue * float3.One; m_BBoxMax_Local = -float.MaxValue * float3.One; int PrimitiveIndex = 0; foreach ( idTech5Map.Model.Surface S in _Entity.m_Model.m_Surfaces ) { m_Primitives[PrimitiveIndex] = new Primitive( this, S ); m_BBoxMin_Local.Min( m_Primitives[PrimitiveIndex].m_BBoxMin ); m_BBoxMax_Local.Max( m_Primitives[PrimitiveIndex].m_BBoxMax ); PrimitiveIndex++; } // Convert BBox to world space m_BBoxMin_World = float.MaxValue * float3.One; m_BBoxMax_World = -float.MaxValue * float3.One; for ( int CornerIndex=0; CornerIndex < 8; CornerIndex++ ) { float X = (CornerIndex >> 0) & 1; float Y = (CornerIndex >> 0) & 1; float Z = (CornerIndex >> 0) & 1; float3 D = m_BBoxMax_Local - m_BBoxMin_Local; float3 lsCorner = m_BBoxMin_Local + new float3( X * D.x, Y * D.y, Z * D.z ); float3 wsCorner = (float3) (new float4( lsCorner, 1.0f ) * m_Local2Parent); m_BBoxMin_World.Min( wsCorner ); m_BBoxMax_World.Max( wsCorner ); } }
public Material( idTech5Map.Material _Material ) { m_ID = (ushort) _Material.m_MaterialIndex; // TODO! m_DiffuseColor = 0.5f * float3.One; }
public Light( Scene _Owner, idTech5Map.Map.Entity _Entity ) : base(_Owner, _Entity) { m_LightType = LIGHT_TYPE.POINT; // TODO // m_LightType = (LIGHT_TYPE) _Light.Type; // m_Color.FromVector3( _Light.Color ); // m_Intensity = _Light.Intensity; // m_HotSpot = _Light.HotSpot; // m_ConeAngle = _Light.ConeAngle; }
public Camera( Scene _Owner, idTech5Map.Map.Entity _Entity ) : base(_Owner, _Entity) { m_FOV = (float) (60.0 * Math.PI / 180.0); }
public Node( Scene _Owner, idTech5Map.Map.Entity _Entity ) { m_Owner = _Owner; m_Owner.m_Nodes.Add( this ); float3 X = new float3( _Entity.m_Local2World.r0.x, _Entity.m_Local2World.r1.x, _Entity.m_Local2World.r2.x ); float3 Y = new float3( _Entity.m_Local2World.r0.y, _Entity.m_Local2World.r1.y, _Entity.m_Local2World.r2.y ); float3 Z = new float3( _Entity.m_Local2World.r0.z, _Entity.m_Local2World.r1.z, _Entity.m_Local2World.r2.z ); float3 P = new float3( _Entity.m_Local2World.r0.w, _Entity.m_Local2World.r1.w, _Entity.m_Local2World.r2.w ); X = ConvTech5( X ); Y = ConvTech5( Y ); Z = ConvTech5( Z ); P = ConvTech5( P ); m_Local2Parent.r0.Set( X, 0 ); m_Local2Parent.r1.Set( Y, 0 ); m_Local2Parent.r2.Set( Z, 0 ); m_Local2Parent.r3.Set( P, 1 ); }