Annotation of /trunk/RexDotMeshLoader/OVertexDeclaration.cs
Parent Directory
|
Revision Log
Revision 48 - (view) (download)
| 1 : | tuco | 48 | /* |
| 2 : | Modified .mesh loader based on the Axiom Graphics Engine Library | ||
| 3 : | which is based on the open source Object Oriented Graphics Engine OGRE. | ||
| 4 : | |||
| 5 : | RexDotMeshLoader by realXtend project. | ||
| 6 : | |||
| 7 : | Axiom Graphics Engine Library | ||
| 8 : | Copyright (C) 2003-2006 Axiom Project Team | ||
| 9 : | The overall design, and a majority of the core engine and rendering code | ||
| 10 : | contained within this library is a derivative of the open source Object Oriented | ||
| 11 : | Graphics Engine OGRE, which can be found at http://ogre.sourceforge.net. | ||
| 12 : | Many thanks to the OGRE team for maintaining such a high quality project. | ||
| 13 : | |||
| 14 : | This library is free software; you can redistribute it and/or | ||
| 15 : | modify it under the terms of the GNU Lesser General Public | ||
| 16 : | License as published by the Free Software Foundation; either | ||
| 17 : | version 2.1 of the License, or (at your option) any later version. | ||
| 18 : | |||
| 19 : | This library is distributed in the hope that it will be useful, | ||
| 20 : | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 21 : | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 22 : | Lesser General Public License for more details. | ||
| 23 : | */ | ||
| 24 : | |||
| 25 : | using System; | ||
| 26 : | using System.Collections; | ||
| 27 : | |||
| 28 : | namespace RexDotMeshLoader | ||
| 29 : | { | ||
| 30 : | public class VertexDeclaration | ||
| 31 : | { | ||
| 32 : | protected ArrayList elements = new ArrayList(); | ||
| 33 : | |||
| 34 : | #region Methods | ||
| 35 : | public VertexElement AddElement( short source, int offset, VertexElementType type, VertexElementSemantic semantic ) | ||
| 36 : | { | ||
| 37 : | return AddElement( source, offset, type, semantic, 0 ); | ||
| 38 : | } | ||
| 39 : | |||
| 40 : | public virtual VertexElement AddElement( short source, int offset, VertexElementType type, VertexElementSemantic semantic, int index ) | ||
| 41 : | { | ||
| 42 : | VertexElement element = new VertexElement( source, offset, type, semantic, index ); | ||
| 43 : | elements.Add( element ); | ||
| 44 : | return element; | ||
| 45 : | } | ||
| 46 : | |||
| 47 : | public VertexElement FindElementBySemantic( VertexElementSemantic semantic ) | ||
| 48 : | { | ||
| 49 : | return FindElementBySemantic( semantic, 0 ); | ||
| 50 : | } | ||
| 51 : | |||
| 52 : | public virtual VertexElement FindElementBySemantic( VertexElementSemantic semantic, short index ) | ||
| 53 : | { | ||
| 54 : | for ( int i = 0; i < elements.Count; i++ ) | ||
| 55 : | { | ||
| 56 : | VertexElement element = (VertexElement)elements[ i ]; | ||
| 57 : | if ( element.Semantic == semantic && element.Index == index ) | ||
| 58 : | return element; | ||
| 59 : | } | ||
| 60 : | return null; | ||
| 61 : | } | ||
| 62 : | |||
| 63 : | public virtual ArrayList FindElementBySource(ushort source) | ||
| 64 : | { | ||
| 65 : | for ( int i = 0; i < elements.Count; i++ ) | ||
| 66 : | { | ||
| 67 : | VertexElement element = (VertexElement)elements[ i ]; | ||
| 68 : | |||
| 69 : | if ( element.Source == source ) | ||
| 70 : | elements.Add( element ); | ||
| 71 : | } | ||
| 72 : | |||
| 73 : | |||
| 74 : | return elements; | ||
| 75 : | } | ||
| 76 : | |||
| 77 : | public VertexElement GetElement(int vIndex) | ||
| 78 : | { | ||
| 79 : | if (vIndex < elements.Count && vIndex >= 0) | ||
| 80 : | return (VertexElement)elements[vIndex]; | ||
| 81 : | else | ||
| 82 : | return null; | ||
| 83 : | } | ||
| 84 : | |||
| 85 : | public virtual int GetVertexSize(short source) | ||
| 86 : | { | ||
| 87 : | int size = 0; | ||
| 88 : | for ( int i = 0; i < elements.Count; i++ ) | ||
| 89 : | { | ||
| 90 : | VertexElement element = (VertexElement)elements[ i ]; | ||
| 91 : | |||
| 92 : | if ( element.Source == source ) | ||
| 93 : | size += element.Size; | ||
| 94 : | } | ||
| 95 : | return size; | ||
| 96 : | } | ||
| 97 : | |||
| 98 : | public VertexElement InsertElement( int position, short source, int offset, VertexElementType type, VertexElementSemantic semantic ) | ||
| 99 : | { | ||
| 100 : | return InsertElement( position, source, offset, type, semantic, 0 ); | ||
| 101 : | } | ||
| 102 : | |||
| 103 : | |||
| 104 : | public virtual VertexElement InsertElement( int position, short source, int offset, VertexElementType type, VertexElementSemantic semantic, int index ) | ||
| 105 : | { | ||
| 106 : | if ( position >= elements.Count ) | ||
| 107 : | { | ||
| 108 : | return AddElement( source, offset, type, semantic, index ); | ||
| 109 : | } | ||
| 110 : | |||
| 111 : | VertexElement element = new VertexElement( source, offset, type, semantic, index ); | ||
| 112 : | elements.Insert( position, element ); | ||
| 113 : | return element; | ||
| 114 : | } | ||
| 115 : | |||
| 116 : | public virtual void RemoveElement(int vIndex) | ||
| 117 : | { | ||
| 118 : | if(vIndex >= 0 && vIndex < elements.Count) | ||
| 119 : | elements.RemoveAt(vIndex); | ||
| 120 : | } | ||
| 121 : | |||
| 122 : | public void ModifyElement( int elemIndex, short source, int offset, VertexElementType type, VertexElementSemantic semantic ) | ||
| 123 : | { | ||
| 124 : | ModifyElement( elemIndex, source, offset, type, semantic, 0 ); | ||
| 125 : | } | ||
| 126 : | |||
| 127 : | public virtual void ModifyElement( int elemIndex, short source, int offset, VertexElementType type, VertexElementSemantic semantic, int index ) | ||
| 128 : | { | ||
| 129 : | elements[ elemIndex ] = new VertexElement( source, offset, type, semantic, index ); | ||
| 130 : | } | ||
| 131 : | |||
| 132 : | public void RemoveElement( VertexElementSemantic semantic ) | ||
| 133 : | { | ||
| 134 : | RemoveElement( semantic, 0 ); | ||
| 135 : | } | ||
| 136 : | |||
| 137 : | public virtual void RemoveElement( VertexElementSemantic semantic, int index ) | ||
| 138 : | { | ||
| 139 : | for ( int i = elements.Count - 1; i >= 0; i-- ) | ||
| 140 : | { | ||
| 141 : | VertexElement element = (VertexElement)elements[ i ]; | ||
| 142 : | |||
| 143 : | if ( element.Semantic == semantic && element.Index == index ) | ||
| 144 : | { | ||
| 145 : | elements.RemoveAt( i ); | ||
| 146 : | } | ||
| 147 : | } | ||
| 148 : | } | ||
| 149 : | |||
| 150 : | public static bool operator ==( VertexDeclaration left, VertexDeclaration right ) | ||
| 151 : | { | ||
| 152 : | if ( left.elements.Count != right.elements.Count ) | ||
| 153 : | return false; | ||
| 154 : | |||
| 155 : | for ( int i = 0; i < right.elements.Count; i++ ) | ||
| 156 : | { | ||
| 157 : | VertexDeclaration a = (VertexDeclaration)left.elements[ i ]; | ||
| 158 : | VertexDeclaration b = (VertexDeclaration)right.elements[ i ]; | ||
| 159 : | |||
| 160 : | if ( !( a == b ) ) | ||
| 161 : | return false; | ||
| 162 : | } | ||
| 163 : | return true; | ||
| 164 : | } | ||
| 165 : | |||
| 166 : | public static bool operator !=( VertexDeclaration left, VertexDeclaration right ) | ||
| 167 : | { | ||
| 168 : | return !( left == right ); | ||
| 169 : | } | ||
| 170 : | |||
| 171 : | #endregion | ||
| 172 : | |||
| 173 : | public int ElementCount | ||
| 174 : | { | ||
| 175 : | get | ||
| 176 : | { | ||
| 177 : | return elements.Count; | ||
| 178 : | } | ||
| 179 : | } | ||
| 180 : | |||
| 181 : | public override bool Equals( object obj ) | ||
| 182 : | { | ||
| 183 : | VertexDeclaration decl = obj as VertexDeclaration; | ||
| 184 : | |||
| 185 : | return ( decl == this ); | ||
| 186 : | } | ||
| 187 : | |||
| 188 : | public override int GetHashCode() | ||
| 189 : | { | ||
| 190 : | return 0; | ||
| 191 : | } | ||
| 192 : | } | ||
| 193 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

