/// <summary> /// Creates a clone of this instance. The method will work for subclasses automatically, /// no need to override it. /// </summary> public MeshStyle Clone() { MeshStyle clone = (MeshStyle)Activator.CreateInstance(_type); clone.CopyFrom(this); return(clone); }
/// <summary> /// Copies all properties of the given style to the current instance (or a subset, if the /// classes don't match). Must be overridden by all subclasses! /// </summary> public virtual void CopyFrom(MeshStyle meshStyle) { _texture = meshStyle._texture; _textureBase = meshStyle._textureBase; TextureRepeat = meshStyle.TextureRepeat; _textureSmoothing = meshStyle._textureSmoothing; }
/// <summary> /// Indicates if the current instance can be batched with the given style. /// To be overridden by subclasses if default behavior is not sufficient. /// The base implementation just checks if the styles are of the same type /// and if the textures are compatible. /// </summary> public virtual bool CanBatchWith(MeshStyle meshStyle) { if (_type == meshStyle._type) { Texture newTexture = meshStyle._texture; if (_texture == null && newTexture == null) { return(true); } if (_texture != null && newTexture != null) { return(_textureBase == meshStyle._textureBase && _textureSmoothing == meshStyle._textureSmoothing && TextureRepeat == meshStyle.TextureRepeat); } return(false); } return(false); }
/// <summary> /// Copies the index data of the style's current target to the target of another style. /// The given offset value will be added to all indices during the process. /// /// <para>This method is used when batching meshes together for rendering. The parameter /// <code>targetStyle</code> will point to the style of a <code>MeshBatch</code> (a /// subclass of <code>Mesh</code>). Subclasses may override this method if they need /// to modify the index data in that process.</para> /// </summary> public virtual void BatchIndexData(MeshStyle targetStyle, int targetIndexId = 0, int offset = 0, int indexId = 0, int numIndices = -1) { _indexData.CopyTo(targetStyle._indexData, targetIndexId, offset, indexId, numIndices); }
/// <summary> /// Copies the vertex data of the style's current target to the target of another style. /// If you pass a matrix, all vertices will be transformed during the process. /// /// Subclasses may override this method if they need to modify the vertex data in that /// process. /// </summary> /// <param name="targetStyle">Points to the style of a MeshBatch</param> /// <param name="targetVertexId">Where to start the copy in the target</param> /// <param name="matrix">If you pass a non-null matrix, the 2D position of each vertex /// will be transformed by that matrix before storing it in the target object.</param> /// <param name="vertexId">position to start copyting from</param> /// <param name="numVertices">Number of vertices to copy</param> public void BatchVertexData(MeshStyle targetStyle, int targetVertexId = 0, Matrix2D matrix = null, int vertexId = 0, int numVertices = -1) { _vertexData.CopyTo(targetStyle._vertexData, vertexId, targetVertexId, numVertices, matrix); }