/// <summary> /// Read a <see cref="CreateMessage"/> and additional payload. /// </summary> /// <param name="reader">Stream to read from</param> /// <returns>True on success.</returns> /// <remarks> /// Read the additional payload to resolve vertex and index counts. /// </remarks> public override bool ReadCreate(BinaryReader reader) { if (!base.ReadCreate(reader)) { return(false); } UInt32 vertexCount; UInt32 indexCount; byte drawType; vertexCount = reader.ReadUInt32(); indexCount = reader.ReadUInt32(); drawType = reader.ReadByte(); DrawType = (MeshDrawType)drawType; if (_vertices == null || _vertices.Length != vertexCount) { _vertices = new Vector3[vertexCount]; } if (_indices == null || _indices.Length != indexCount) { _indices = null; if (indexCount > 0) { _indices = new int[indexCount]; } } _normals = null; return(true); }
/// <summary> /// Handle triangle count. /// </summary> /// <param name="obj"></param> /// <param name="msg"></param> /// <param name="packet"></param> /// <param name="reader"></param> /// <returns></returns> protected override Error PostHandleMessage(CreateMessage msg, PacketBuffer packet, BinaryReader reader, ShapeCache cache, int shapeIndex) { int vertexCount = reader.ReadInt32(); int indexCount = reader.ReadInt32(); MeshDrawType drawType = (MeshDrawType)reader.ReadByte(); RenderMesh mesh = new RenderMesh(drawType, vertexCount, indexCount); MeshEntry meshEntry = new MeshEntry { Mesh = mesh, CalculateNormals = (msg.Flags & (ushort)MeshShapeFlag.CalculateNormals) != 0, DrawScale = 0.0f }; if (packet.Header.VersionMajor == 0 && packet.Header.VersionMinor == 1) { // Legacy handling. meshEntry.DrawScale = 0.0f; } else { meshEntry.DrawScale = reader.ReadSingle(); } cache.SetShapeDataByIndex(shapeIndex, meshEntry); if (meshEntry.CalculateNormals) { _toCalculateNormals.Add(mesh); } return(base.PostHandleMessage(msg, packet, reader, cache, shapeIndex)); }
/// <summary> /// Create a mesh shape. /// </summary> /// <param name="drawType">Mesh topology.</param> /// <param name="vertices">Vertex data.</param> /// <param name="indices">Index data. Must match topology.</param> /// <param name="id">The shape ID. Zero for transient shapes.</param> /// <param name="category">Category to which the shape belongs.</param> /// <param name="position">Local position.</param> /// <param name="rotation">Local rotation.</param> /// <param name="scale">Local scaling.</param> public MeshShape(MeshDrawType drawType, Vector3[] vertices, int[] indices, uint id, ushort category, Vector3 position, Quaternion rotation, Vector3 scale) : base((ushort)Tes.Net.ShapeID.Mesh, id, category) { IsComplex = true; _vertices = vertices; _indices = indices ?? new int[0]; DrawType = drawType; Position = position; Rotation = rotation; Scale = scale; }
/// <summary> /// Create a new mesh resource. /// </summary> /// <param name="id">The unique mesh resource ID for this mesh.</param> /// <param name="drawType">Defines the topology.</param> /// <param name="components">Identifies the required <see cref="MeshComponentFlag"/>.</param> public SimpleMesh(uint id, MeshDrawType drawType = MeshDrawType.Triangles, MeshComponentFlag components = MeshComponentFlag.Vertex | MeshComponentFlag.Index) { ID = id; DrawType = (byte)MeshDrawType.Triangles; Tint = 0xffffffffu; Transform = Matrix4.Identity; Components = components; _vertices = new List <Vector3>(); if ((components & MeshComponentFlag.Index) == MeshComponentFlag.Index) { _indices = new List <int>(); } CalculateNormals = true; }
/// <summary> /// Create a mesh shape. /// </summary> /// <param name="drawType">Mesh topology.</param> /// <param name="vertices">Vertex data.</param> /// <param name="indices">Index data. Must match topology.</param> /// <param name="id">The shape ID. Zero for transient shapes.</param> /// <param name="position">Local position.</param> /// <param name="rotation">Local rotation.</param> /// <param name="scale">Local scaling.</param> public MeshShape(MeshDrawType drawType, Vector3[] vertices, int[] indices, uint id, Vector3 position, Quaternion rotation, Vector3 scale) : base((ushort)Tes.Net.ShapeID.Mesh, id) { IsComplex = true; _vertices = vertices; _indices = indices ?? new int[0]; DrawType = drawType; Position = position; Rotation = rotation; Scale = scale; if (drawType == MeshDrawType.Points) { ColourByHeight = true; } }
/// <summary> /// Read a <see cref="CreateMessage"/> and additional payload. /// </summary> /// <param name="packet">The buffer from which the reader reads.</param> /// <param name="reader">Stream to read from</param> /// <returns>True on success.</returns> /// <remarks> /// Read the additional payload to resolve vertex and index counts. /// </remarks> public override bool ReadCreate(PacketBuffer packet, BinaryReader reader) { if (!base.ReadCreate(packet, reader)) { return(false); } UInt32 vertexCount; UInt32 indexCount; byte drawType; vertexCount = reader.ReadUInt32(); indexCount = reader.ReadUInt32(); drawType = reader.ReadByte(); DrawType = (MeshDrawType)drawType; if (_vertices == null || _vertices.Length != vertexCount) { _vertices = new Vector3[vertexCount]; } if (_indices == null || _indices.Length != indexCount) { _indices = null; if (indexCount > 0) { _indices = new int[indexCount]; } } _normals = null; if (packet.Header.VersionMajor != 0 || packet.Header.VersionMajor == 0 && packet.Header.VersionMinor >= 2) { _drawWeight = reader.ReadSingle(); } else { // Legacy support _drawWeight = 0; } return(true); }
/// <summary> /// Converts <paramref name="drawType"/> to the equivalent Unity <c>Topology</c>. /// </summary> /// <param name="drawType">The Tes topology.</param> /// <returns>The equivalent Unity <c>Topology</c></returns> /// <exception cref="NotImplementedException">Thrown when <paramref name="drawType"/> is /// not supported by the Unity implementation.</exception> public static MeshTopology DrawTypeToTopology(MeshDrawType drawType) { switch (drawType) { case MeshDrawType.Points: // No break. case MeshDrawType.Voxels: return(MeshTopology.Points); case MeshDrawType.Lines: return(MeshTopology.Lines); case MeshDrawType.Triangles: return(MeshTopology.Triangles); default: break; } throw new NotImplementedException("Unsupported draw type."); }
/// <summary> /// Create a mesh shape. /// </summary> /// <param name="drawType">Mesh topology.</param> /// <param name="vertices">Vertex data.</param> /// <param name="id">The shape ID. Zero for transient shapes.</param> /// <param name="category">Optional display category for the shape.</param> public MeshShape(MeshDrawType drawType, Vector3[] vertices, uint id = 0, ushort category = 0) : this(drawType, vertices, null, id) { }
/// <summary> /// Create a mesh shape. /// </summary> /// <param name="drawType">Mesh topology.</param> /// <param name="vertices">Vertex data.</param> /// <param name="id">The shape ID. Zero for transient shapes.</param> /// <param name="category">Category to which the shape belongs.</param> /// <param name="position">Local position.</param> /// <param name="rotation">Local rotation.</param> /// <param name="scale">Local scaling.</param> public MeshShape(MeshDrawType drawType, Vector3[] vertices, uint id, ushort category, Vector3 position, Quaternion rotation, Vector3 scale) : this(drawType, vertices, null, id, category, position, rotation, scale) { }
public RenderMesh(MeshDrawType drawType, int vertexCount, int indexCount = 0) { SetVertexCount(vertexCount); SetIndexCount(indexCount); _drawType = drawType; }
/// <summary> /// Create a mesh shape. /// </summary> /// <param name="drawType">Mesh topology.</param> /// <param name="vertices">Vertex data.</param> /// <param name="indices">Index data. Must match topology.</param> /// <param name="position">Local position.</param> /// <param name="rotation">Local rotation.</param> public MeshShape(MeshDrawType drawType, Vector3[] vertices, int[] indices, Vector3 position, Quaternion rotation) : this(drawType, vertices, indices, position, rotation, Vector3.One) { }
/// <summary> /// Create a mesh shape. /// </summary> /// <param name="drawType">Mesh topology.</param> /// <param name="vertices">Vertex data.</param> /// <param name="position">Local position.</param> /// <param name="rotation">Local rotation.</param> public MeshShape(MeshDrawType drawType, Vector3[] vertices, Vector3 position, Quaternion rotation) : this(drawType, vertices, null, position, rotation) { }
/// <summary> /// Create a mesh shape. /// </summary> /// <param name="drawType">Mesh topology.</param> /// <param name="vertices">Vertex data.</param> /// <param name="indices">Index data. Must match topology.</param> /// <param name="id">The shape ID. Zero for transient shapes.</param> /// <param name="category">Category to which the shape belongs.</param> public MeshShape(MeshDrawType drawType, Vector3[] vertices, int[] indices, uint id = 0, ushort category = 0) : this(drawType, vertices, indices, id, category, Vector3.Zero, Quaternion.Identity, Vector3.One) { }
/// <summary> /// Create a mesh shape. /// </summary> /// <param name="drawType">Mesh topology.</param> /// <param name="vertices">Vertex data.</param> /// <param name="id">The shape ID. Zero for transient shapes.</param> /// <param name="category">Category to which the shape belongs.</param> /// <param name="position">Local position.</param> public MeshShape(MeshDrawType drawType, Vector3[] vertices, uint id, ushort category, Vector3 position) : this(drawType, vertices, null, id, category, position) { }
/// <summary> /// Create a mesh shape. /// </summary> /// <param name="drawType">Mesh topology.</param> /// <param name="vertices">Vertex data.</param> /// <param name="indices">Index data. Must match topology.</param> /// <param name="id">The shape ID. Zero for transient shapes.</param> /// <param name="category">Category to which the shape belongs.</param> /// <param name="position">Local position.</param> /// <param name="rotation">Local rotation.</param> public MeshShape(MeshDrawType drawType, Vector3[] vertices, int[] indices, uint id, ushort category, Vector3 position, Quaternion rotation) : this(drawType, vertices, indices, id, category, position, rotation, Vector3.One) { }
/// <summary> /// Create a mesh shape. /// </summary> /// <param name="drawType">Mesh topology.</param> /// <param name="vertices">Vertex data.</param> /// <param name="id">The shape ID. Zero for transient shapes.</param> /// <param name="position">Local position.</param> public MeshShape(MeshDrawType drawType, Vector3[] vertices, uint id, Vector3 position) : this(drawType, vertices, null, id, position) { }
/// <summary> /// Create a mesh shape. /// </summary> /// <param name="drawType">Mesh topology.</param> /// <param name="vertices">Vertex data.</param> /// <param name="indices">Index data. Must match topology.</param> /// <param name="id">The shape ID. Zero for transient shapes.</param> /// <param name="position">Local position.</param> public MeshShape(MeshDrawType drawType, Vector3[] vertices, int[] indices, uint id, Vector3 position) : this(drawType, vertices, indices, id, position, Quaternion.Identity, Vector3.One) { }