/// <summary> /// Try to find all <see cref="Vertex"/> with a given property value. /// </summary> /// <param name="value">The property value to look for</param> /// <param name="polymorphic">If true, also look for property value matching vertices of property <see cref="VertexType"/> sub classes</param> /// <returns>Enumeration of matching vertices</returns> public IEnumerable <Vertex> GetPropertyVertices(T value, bool polymorphic = false) { VertexId elementId = -1; VertexType vertexType = MyGraph.VertexTypes[TypeId]; if (m_valueIndexUnique == null || m_valueIndexUnique.TryGetValue(value, out elementId) == false) { BTreeSet <ElementId> elementIds; if (m_valueIndex != null && m_valueIndex.TryGetValue(value, out elementIds)) { foreach (ElementId eId in elementIds) { Vertex vertex = vertexType.GetVertex(eId, polymorphic, false); if (vertex != null) { yield return(vertex); } } } } if (elementId != -1) { Vertex vertex = vertexType.GetVertex(elementId, polymorphic, false); if (vertex != null) { yield return(vertex); } } }
public Vertex(VertexType type, float x, float y, float z) { Type = type; X = x; Y = y; Z = z; }
public static void DrawDiagonal() { sortedList = Points.OrderByDescending(v => v.y).ToList(); MaxIndex = Points.IndexOf(sortedList.Last()); MinIndex = Points.IndexOf(sortedList.First()); int MostLeftPointIndex = Points.IndexOf(Points.OrderBy(v => v.x).First()); LeftChain = ((MinIndex < MostLeftPointIndex && MostLeftPointIndex < MaxIndex) || (MaxIndex < MostLeftPointIndex && MostLeftPointIndex < MinIndex)); for (int i = 0; i < sortedList.Count; i++) { int TargetIndex = Points.IndexOf(sortedList[i]); Vector3 o = sortedList[i]; Vector3 a = GetListElementWithLoop(Points, TargetIndex - 1); Vector3 b = GetListElementWithLoop(Points, TargetIndex + 1); VertexType t = GetVertexType(a, o, b); Debug.Log("Target Vertex : " + TargetIndex + t.ToString() + ", o : " + o + ", a : " + a + ", b : " + b); switch (t) { case VertexType.StartVertex: HandleStartVertex(TargetIndex); break; case VertexType.SplitVertex: HandleSplitVertex(TargetIndex); break; case VertexType.MergeVertex: HandleMergeVertex(TargetIndex); break; case VertexType.RegularVertex: HandleRegularVertex(TargetIndex); break; case VertexType.EndVertex: HandleEndVertex(TargetIndex); break; } } }
public CodeVertex(VertexType Typ, long BrTo, string Cde, long Adr) { Type = Typ; BranchTo = BrTo; Code = Cde; Addr = Adr; }
public VertexSerialize(string key, float x, float y, VertexType type) { Key = key; X = x; Y = y; Type = type; }
public override string GenerateSharedVertexShader(VertexType vertex, ShaderStage stage) { var gen = new HalogramGenerator(); var bytecode = gen.GenerateSharedVertexShader(vertex, stage).Bytecode; return(D3DCompiler.Disassemble(bytecode)); }
/// <summary> /// Gets an edge given an edge id. Throws if no such edge exist. /// </summary> /// <param name="edgeId">The id of the edge</param> /// <returns>The edge with matching id if it exists</returns> public Edge GetEdge(EdgeId edgeId) { if (Unrestricted) { UnrestrictedEdge headTail; if (m_unrestrictedEdges.TryGetValue(edgeId, out headTail)) { VertexType vt = headTail.m_headVertexType; Vertex head = vt.GetVertex(headTail.m_headVertexId); vt = headTail.m_tailVertexType; Vertex tail = vt.GetVertex(headTail.m_tailVertexId); return(new Edge(MyGraph, this, edgeId, head, tail)); } } else { UInt64 vertexVertex; if (m_restrictedEdges.TryGetValue(edgeId, out vertexVertex)) { VertexId headId = (VertexId)(vertexVertex >> 32); Vertex head = HeadType.GetVertex(headId); Vertex tail = TailType.GetVertex((VertexId)vertexVertex); return(new Edge(MyGraph, this, edgeId, head, tail)); } } throw new EdgeDoesNotExistException(); }
public ShaderGeneratorResult GenerateSharedVertexShader(VertexType vertexType, ShaderStage entryPoint) { if (!IsVertexFormatSupported(vertexType) || !IsEntryPointSupported(entryPoint)) { return(null); } List <D3D.SHADER_MACRO> macros = new List <D3D.SHADER_MACRO>(); macros.Add(new D3D.SHADER_MACRO { Name = "_VERTEX_SHADER_HELPER_HLSLI", Definition = "1" }); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <ShaderStage>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <VertexType>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Shared.ShaderType>()); macros.Add(ShaderGeneratorBase.CreateMacro("calc_vertex_transform", vertexType, "calc_vertex_transform_", "")); macros.Add(ShaderGeneratorBase.CreateMacro("transform_dominant_light", vertexType, "transform_dominant_light_", "")); macros.Add(ShaderGeneratorBase.CreateVertexMacro("input_vertex_format", vertexType)); macros.Add(ShaderGeneratorBase.CreateMacro("shaderstage", entryPoint, "k_shaderstage_")); macros.Add(ShaderGeneratorBase.CreateMacro("vertextype", vertexType, "k_vertextype_")); macros.Add(ShaderGeneratorBase.CreateMacro("shadertype", Shared.ShaderType.Cortana, "shadertype_")); byte[] shaderBytecode = ShaderGeneratorBase.GenerateSource(@"glvs_cortana.hlsl", macros, $"entry_{entryPoint.ToString().ToLower()}", "vs_3_0"); return(new ShaderGeneratorResult(shaderBytecode)); }
public Vertex(VertexType type, Vector3 v) { Type = type; X = v.x; Y = v.y; Z = v.z; }
private void DialogSubmitButton_Click(object sender, EventArgs e) { float number; Key = KeyTextbox.Text; if (float.TryParse(XTextbox.Text, out number)) { X = number; } if (float.TryParse(YTextbox.Text, out number)) { Y = number; } switch (ComboVertexType.SelectedIndex) { case 0: Type = VertexType.Junction; break; case 1: Type = VertexType.RestArea; break; case 2: Type = VertexType.Stop; break; } }
public bool onlySelectedFaces = false; // only simplify selected faces // Start is called before the first frame update void Start() { heap = new List<Vector3>(); tempHeap = new List<Vector3>(); instr = new VertexType(); instr.pair = new Pair(); instr.visited = new List<bool>(); meshCopy = GetComponent<MeshFilter>().mesh; startTime = Time.time; if (GetComponent<MeshFilter>().mesh != null) { vertices = GetComponent<MeshFilter>().mesh.vertices; triangles = GetComponent<MeshFilter>().mesh.triangles; } else { Debug.LogWarning("ERROR"); } currentTime = Time.time; Init_heap(); DoOptimization(); meshCopy.RecalculateNormals(); meshCopy.vertices = vertices; meshCopy.triangles = triangles; GetComponent<MeshFilter>().mesh = meshCopy; }
private Vertex CreateVertex(Vector3 point, VertexType type) { Vertex v = new Vertex(point, null, type); v.LoadModel(); return(v); }
protected Vertex(int row, int positionInRow, VertexType type, Vector2 pxCoords) { Row = row; PositionInRow = positionInRow; Type = type; PxCoords = pxCoords; }
public Mesh createQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, bool isClockwise = true) { shapeKind = ShapeKind.RECT; vertexType = VertexType.MESH; clearMesh(); mesh.name = "Quad"; mesh.vertices = new Vector3[] { new Vector3(x1, y1, 0.0f), new Vector3(x2, y2, 0.0f), new Vector3(x3, y3, 0.0f), new Vector3(x4, y4, 0.0f), }; var uv = new Vector2[] { new Vector2(0.0f, 0.0f), new Vector2(1.0f, 0.0f), new Vector2(1.0f, 1.0f), new Vector2(0.0f, 1.0f), }; int[] triangles = new int[] { 2, 1, 0, 0, 3, 2 }; int[] wireIndices = new int[] { 2, 1, 0, 3, 2 }; mesh.subMeshCount = 2; setMeshTriangles(triangles, uv, 0); recalc(mesh); //setWireframeMeshTriangles(triangles, 1); setWireframeMeshIndices(wireIndices, 1, MeshTopology.LineStrip); return(mesh); }
/// <summary> /// Creates a new edge type. /// </summary> /// <param name="aTypeId">The id to use for the new edge type</param> /// <param name="aTypeName">A type name to use</param> /// <param name="tailType">Restrict tail vertex to a certain vertex type</param> /// <param name="headType">Restrict head vertex to a certain vertex type</param> /// <param name="birectional">Is this edge type bidirectional (going both ways)</param> /// <param name="baseType">A base type can be specified</param> /// <param name="graph">The owning graph</param> public EdgeType(TypeId aTypeId, string aTypeName, VertexType tailType, VertexType headType, bool birectional, EdgeType baseType, Graph graph) { this.graph = graph; this.baseType = baseType; subType = new VelocityDbList <EdgeType>(); if (baseType != null) { baseType.subType.Add(this); } this.birectional = birectional; typeId = aTypeId; typeName = aTypeName; this.tailType = tailType; this.headType = headType; if (Unrestricted) { unrestrictedEdges = new BTreeMap <EdgeId, UnrestrictedEdge>(null, graph.Session); } else { restrictedEdges = new BTreeMap <EdgeId, ulong>(null, graph.Session); } stringToPropertyType = new BTreeMap <string, PropertyType>(null, graph.Session); edgeRanges = new VelocityDbList <Range <EdgeId> >(); }
private void SetVertexShader(DeviceContext context, VertexType type) { VertexShader vs = vspnct; switch (type) { case VertexType.PT: vs = vspt; break; case VertexType.PCT: vs = vspct; break; case VertexType.Default: vs = vspnct; break; case VertexType.DefaultEx: vs = vspnctx; break; default: break; } context.VertexShader.Set(vs); }
void Create_Buffer() { Collection <VertexType> tmp = new Collection <VertexType>(); for (int i = 0; i < m_Vector_Normals.Count() / 3; i++) { VertexType VT = new VertexType(); VT.pos = new Vector3(m_Vector_Vertex[i * 3 + 0][0], m_Vector_Vertex[i * 3 + 0][1], m_Vector_Vertex[i * 3 + 0][2]); VT.uv = new Vector2(m_Vector_UV[i * 3 + 0][0], m_Vector_UV[i * 3 + 0][1]); VT.norm = new Vector3(m_Vector_Normals[i * 3 + 0][0], m_Vector_Normals[i * 3 + 0][1], m_Vector_Normals[i * 3 + 0][2]); tmp.Add(VT); VT.pos = new Vector3(m_Vector_Vertex[i * 3 + 1][0], m_Vector_Vertex[i * 3 + 1][1], m_Vector_Vertex[i * 3 + 1][2]); VT.uv = new Vector2(m_Vector_UV[i * 3 + 1][0], m_Vector_UV[i * 3 + 1][1]); VT.norm = new Vector3(m_Vector_Normals[i * 3 + 1][0], m_Vector_Normals[i * 3 + 1][1], m_Vector_Normals[i * 3 + 1][2]); tmp.Add(VT); VT.pos = new Vector3(m_Vector_Vertex[i * 3 + 2][0], m_Vector_Vertex[i * 3 + 2][1], m_Vector_Vertex[i * 3 + 2][2]); VT.uv = new Vector2(m_Vector_UV[i * 3 + 2][0], m_Vector_UV[i * 3 + 2][1]); VT.norm = new Vector3(m_Vector_Normals[i * 3 + 2][0], m_Vector_Normals[i * 3 + 2][1], m_Vector_Normals[i * 3 + 2][2]); tmp.Add(VT); } m_Ready_To_Buffer = tmp; }
/// <summary> /// Return the vertex referenced by the provided object identifier. /// If no vertex is referenced by that identifier, then return null. /// </summary> /// <param name="id">the identifier of the vertex to retrieved from the graph, must be a UInt64</param> /// <returns>the vertex referenced by the provided identifier or null when no such vertex exists</returns> public IVertex GetVertex(object id) { if (id == null) { throw new ArgumentException("id may not be null, it should be a UInt64"); } if (id is UInt64) { UInt64 fullId = (UInt64)id; VertexTypeId vertexTypeId = (VertexTypeId)(fullId >> 32); VertexType vt = vertexType[vertexTypeId]; VertexId vertexId = (VertexId)fullId; Vertex vertex = vt.GetVertex(vertexId); return(vertex); } if (id is string) { UInt64 fullId; if (UInt64.TryParse(id as string, out fullId)) { VertexTypeId vertexTypeId = (VertexTypeId)(fullId >> 32); VertexType vt = vertexType[vertexTypeId]; VertexId vertexId = (VertexId)fullId; Vertex vertex = vt.GetVertex(vertexId); return(vertex); } } return(null); }
/// <summary> /// numerates all elements satisfying the given condition for the given property and value range /// </summary> /// <param name="property">Property we are looking for</param> /// <param name="condition"> filter function, applied with in graph value as 1st parameter, lower as 2nd and higher as 3rd parameter.</param> /// <param name="lower">lower value in filtering</param> /// <param name="higher">higher value in filtering</param> /// <returns></returns> public IEnumerable <IElement> Select(PropertyType property, Func <IComparable, IComparable, IComparable, Boolean> condition, IComparable lower, IComparable higher) { if (property.IsVertexProperty) { VertexType vt = vertexType[property.TypeId]; foreach (Vertex vertex in vt.GetVertices()) { IComparable v = property.GetPropertyValue(vertex.VertexId); if (condition(v, lower, higher)) { yield return(vertex); } } } else { EdgeType et = edgeType[property.TypeId]; foreach (Edge edge in et.GetEdges()) { IComparable v = property.GetPropertyValue(edge.EdgeId); if (condition(v, lower, higher)) { yield return(edge); } } } }
/// <summary> /// 处理顶点 /// </summary> /// <param name="point">Point.</param> private void HandleVertex(Vector2 point) { DoubleLink <Vector2> .Node node = _Vertexes.Find(point); if (node == null) { return; } VertexType type = TypeOfVertex(node); Debug.Log(type); switch (type) { case VertexType.Start: HandleStartVertex(node); break; case VertexType.End: HandleEndVertex(node); break; case VertexType.Split: HandleSpiltVertex(node); break; case VertexType.Merge: HandleMergeVertex(node); break; case VertexType.Regular: HandleRegularVertex(node); break; default: break; } }
public override bool SetInputLayout(DeviceContext context, VertexType type) { InputLayout l; if (layouts.TryGetValue(type, out l)) { VertexShader vs = shadowvs; switch (type) { case VertexType.PBBNCT: case VertexType.PBBNCTX: case VertexType.PBBNCTT: case VertexType.PBBNCTTT: case VertexType.PBBNCCT: case VertexType.PBBNCCTT: case VertexType.PBBNCCTX: case VertexType.PBBNCTTX: case VertexType.PBBNCTTTX: case VertexType.PBBNCCTTX: vs = shadowvs_skin; break; } context.VertexShader.Set(vs); context.InputAssembler.InputLayout = l; return(true); } return(false); }
public Vertex(double x, double y, float up, int steinerPointWeight) : base(x, y, 0) { this.up = up; this.type = VertexType.InputVertex; this.steinerPointWeight = steinerPointWeight; }
public void AskForBuilding(Vertex vertex, VertexType type) { if (type != VertexType.EMPTY) { wantedVertex = vertex; wantedVertexType = type; SetActiveRhythm(true); int index = Random.Range(0, musics.Length); blueSpawner.GetComponent <ArrowSpawner>().StartMusic(musics[index].bps, new List <float>(musics[index].notes[0].notesInterval)); redSpawner.GetComponent <ArrowSpawner>().StartMusic(musics[index].bps, new List <float>(musics[index].notes[1].notesInterval)); yellowSpawner.GetComponent <ArrowSpawner>().StartMusic(musics[index].bps, new List <float>(musics[index].notes[2].notesInterval)); greenSpawner.GetComponent <ArrowSpawner>().StartMusic(musics[index].bps, new List <float>(musics[index].notes[3].notesInterval)); buildingCost = musics[index].notes[0].notesInterval.Count + musics[index].notes[1].notesInterval.Count + musics[index].notes[2].notesInterval.Count + musics[index].notes[3].notesInterval.Count; for (int i = 0; i < 4; i++) { if (musics[index].notes[i].notesInterval.Count > 0) { if (musics[index].notes[i].notesInterval[musics[index].notes[i].notesInterval.Count - 1] > musicLength) { musicLength = musics[index].notes[i].notesInterval[musics[index].notes[i].notesInterval.Count - 1] * musics[index].bps; } } } } }
public Vertex(Double2 prev, Double2 cur, Double2 next) { Current = cur; NextEdge = new Edge(cur, next); OutgoingEdges = new AvlTree <Edge, Edge>(Edge.AngleComparer); OutgoingEdges.Insert(NextEdge, NextEdge); IncomingEdges = new AvlTree <Edge, Edge>(Edge.AngleComparer); // Comparison variables int comparisonCP = CanonicalComparer.Default.Compare(cur, prev); int comparisonCN = CanonicalComparer.Default.Compare(cur, next); bool reflex = (prev - cur).AngleBetween(next - cur) > 0; // Compute the type of the vertex // Both lie below: if (comparisonCP > 0 && comparisonCN > 0) { Type = reflex ? VertexType.Split : VertexType.Start; } // Both lie above: else if (comparisonCP < 0 && comparisonCN < 0) { Type = reflex ? VertexType.Merge : VertexType.End; } // We have to take account if the vertex is on the outer or the inner contour else { Type = comparisonCN > 0 ? VertexType.RegularLeft : VertexType.RegularRight; } }
bool UpdateBuffers(DeviceContext deviceContext, int positionX, int positionY) { if (positionX == previousPosX && positionY == previousPosY) { return(true); } previousPosX = positionX; previousPosY = positionY; var left = (float)-screenWidth / 2 + positionX; var right = left + bitmapWidth; var top = (float)screenHeight / 2 - positionY; var bottom = top - bitmapHeight; var vertices = new VertexType[vertexCount]; vertices[0].Position = new Vector3(left, top, 0.0f); vertices[0].Texture = new Vector2(0.0f, 0.0f); vertices[1].Position = new Vector3(right, bottom, 0.0f); vertices[1].Texture = new Vector2(1.0f, 1.0f); vertices[2].Position = new Vector3(left, bottom, 0.0f); vertices[2].Texture = new Vector2(0.0f, 1.0f); vertices[3].Position = new Vector3(left, top, 0.0f); vertices[3].Texture = new Vector2(0.0f, 0.0f); vertices[4].Position = new Vector3(right, top, 0.0f); vertices[4].Texture = new Vector2(1.0f, 0.0f); vertices[5].Position = new Vector3(right, bottom, 0.0f); vertices[5].Texture = new Vector2(1.0f, 1.0f); deviceContext.UpdateSubresource(vertices, vertexBuffer); return(true); }
void CalcToolpath(ProcessObject obj, VertexType vertex) { if (obj == null) { return; } ProcessObject srcObj = obj.ConnectObject[vertex.Index()]; VertexType srcVertex = obj.ConnectVertex[vertex.Index()]; SideType containedSide = vertex != srcVertex ? srcObj.Side : srcObj.Side.Opposite(); if (obj.IsExactly[vertex.Index()] != srcObj.IsExactly[srcVertex.Index()] || obj.Side != containedSide || (obj.ToolpathCurve == null && obj.ProcessActions == null)) { obj.IsExactly[vertex.Index()] = srcObj.IsExactly[srcVertex.Index()]; vertex = vertex.Opposite(); if ((obj.Side != containedSide && obj.ConnectObject[vertex.Index()] != null) || (obj.ToolpathCurve == null && obj.ProcessActions == null)) { obj.Side = containedSide; obj.IsExactly[vertex.Index()] = CalcExactlyEnd(obj, vertex); } obj.Side = containedSide; ConstructToolpathObject(obj); CalcToolpath(obj.ConnectObject[vertex.Index()], obj.ConnectVertex[vertex.Index()]); } }
static void TestSharedVertexBlack(VertexType vertexType, ShaderStage stage) { var gen = new ShaderBlackGenerator(); var bytecode = gen.GenerateSharedVertexShader(vertexType, stage).Bytecode; WriteShaderFile($"generated_shader_black_{stage.ToString().ToLower()}_{vertexType.ToString().ToLower()}.glvs", D3DCompiler.Disassemble(bytecode)); }
/// <summary> /// Creates a new mesh with enough space to hold the a number of primitives using the specified layout. All indices /// will be part of a single sub-mesh. /// </summary> /// <param name="numVertices">Number of vertices in the mesh.</param> /// <param name="numIndices">Number of indices in the mesh. </param> /// <param name="topology">Determines how should the provided indices be interpreted by the pipeline. Default option /// is a triangle list, where three indices represent a single triangle.</param> /// <param name="usage">Optimizes performance depending on planned usage of the mesh.</param> /// <param name="vertex">Controls how are vertices organized in the vertex buffer and what data they contain.</param> /// <param name="index">Size of indices, use smaller size for better performance, however be careful not to go over /// the number of vertices limited by the size.</param> public Mesh(int numVertices, int numIndices, MeshTopology topology = MeshTopology.TriangleList, MeshUsage usage = MeshUsage.Default, VertexType vertex = VertexType.Position, IndexType index = IndexType.Index32) { SubMesh[] subMeshes = { new SubMesh(0, numIndices, topology) }; Internal_CreateInstance(this, numVertices, numIndices, subMeshes, usage, vertex, index); }
public ShaderGeneratorResult GenerateVertexShader(VertexType vertexType, ShaderStage entryPoint) { if (!TemplateGenerationValid) { throw new System.Exception("Generator initialized with shared shader constructor. Use template constructor."); } return(null); }
public override IEnumerable <Vertex> GetPropertyVertices(IComparable value, VertexType vertexType) { if (IsVertexProperty == false) { throw new InvalidTypeIdException(); } return(GetPropertyVertices((T)value, vertexType)); }
/// <summary> /// Initializes a new instance of the <see cref="Vertex" /> class. /// </summary> /// <param name="x">The x coordinate of the vertex.</param> /// <param name="y">The y coordinate of the vertex.</param> /// <param name="mark">The boundary mark.</param> /// <param name="attribs">The number of point attributes.</param> public Vertex(double x, double y, int mark, int attribs) : base(x, y, mark) { this.type = VertexType.InputVertex; if (attribs > 0) { this.attributes = new double[attribs]; } }
public FSVertex(string name, string fullName, string friendlySize, VertexType vertexType, DateTime created, DateTime accessed, DateTime modified) { this.Name = name; this.FullName = fullName; this.FriendlySize = friendlySize; this.VertexType = vertexType; this.Created = created; this.Accessed = accessed; this.Modified = modified; }
public Vertex(Vertex v) { this.x = v.GetX(); this.y = v.GetY(); this.prevVertex = null; this.nextVertex = null; this.bisectorVertex = v.bisectorVertex; this.processed = v.Processed; this.type = v.Type; }
static StockVertex CreateVertex(SortStock sd, VertexType vtp) { if (sd == null) { return null; } StockVertex sv = new StockVertex(); sv.FindType = VertexFindType.Automatic; sv.VertType = vtp; sv.VertexDate = sd.CurrentDate; return sv; }
public Vertex(double x, double y) { this.x = x; this.y = y; this.prevVertex = null; this.nextVertex = null; this.bisectorVertex = null; this.prevLS = null; this.nextLS = null; this.processed = false; this.type = VertexType.Undefined; }
public RegisterAsAttribute (VertexAttribute Format, VertexType Type) { format = Format; switch (format) { case VertexAttribute.POSITION: shaderLocation=0; break; case VertexAttribute.COLOR: shaderLocation=1; break; case VertexAttribute.UV: shaderLocation=2; break; case VertexAttribute.NORMAL: shaderLocation=3; break; } type = Type; }
/// <summary> /// Creates a new mesh with enough space to hold the a number of primitives using the specified layout. Indices can /// be references by multiple sub-meshes. /// </summary> /// <param name="numVertices">Number of vertices in the mesh.</param> /// <param name="numIndices">Number of indices in the mesh. </param> /// <param name="subMeshes">Defines how are indices separated into sub-meshes, and how are those sub-meshes rendered. /// Sub-meshes may be rendered independently.</param> /// <param name="usage">Optimizes performance depending on planned usage of the mesh.</param> /// <param name="vertex">Controls how are vertices organized in the vertex buffer and what data they contain.</param> /// <param name="index">Size of indices, use smaller size for better performance, however be careful not to go over /// the number of vertices limited by the size.</param> public Mesh(int numVertices, int numIndices, SubMesh[] subMeshes, MeshUsage usage = MeshUsage.Default, VertexType vertex = VertexType.Position, IndexType index = IndexType.Index32) { Internal_CreateInstance(this, numVertices, numIndices, subMeshes, usage, vertex, index); }
public Vertex(Vector3 data, VertexType t, Compression c) { Usage = t; Compression = c; Position.X = data.X; Position.Y = data.Y; Position.Z = data.Z; }
private static extern void Internal_CreateInstance(MeshData instance, int numVertices, int numIndices, VertexType vertex, IndexType index);
/// <summary> /// Creates a new mesh data that can hold number of vertices described by the provided vertex layout as well as a /// number of indices of the provided type. /// </summary> /// <param name="numVertices">Number of vertices in the mesh.</param> /// <param name="numIndices">Number of indices in the mesh. </param> /// <param name="vertex">Controls how are vertices organized in the vertex buffer and what data they contain.</param> /// <param name="index">Size of indices, use smaller size for better performance, however be careful not to go over /// the number of vertices limited by the size.</param> public MeshData(int numVertices, int numIndices, VertexType vertex = VertexType.Position, IndexType index = IndexType.Index32) { Internal_CreateInstance(this, numVertices, numIndices, vertex, index); }
static extern void VideoDriver_DrawVertexPrimitiveList(IntPtr videodriver, IntPtr[] vertices, int vertexCount, ushort[] indexList, int triangleCount, VertexType vType, PrimitiveType pType);
public Section(Tag tag, CompressionInfo boundingBox) { BinaryReader br = new BinaryReader(tag.TagStream); int StartOffset = (int)tag.TagStream.Position; buffer = br.ReadBytes(Size); tag.TagStream.Position = StartOffset; VertexType = (VertexType)br.ReadInt32(); VertexCount = br.ReadInt16(); TriangleCount = br.ReadInt16(); tag.TagStream.Position = StartOffset + 26; CompressionFlags = (Compression)br.ReadInt32(); tag.TagStream.Position = StartOffset + 56; RawOffset = br.ReadInt32(); RawSize = br.ReadInt32(); br.ReadInt32(); RawDataSize = br.ReadInt32(); tag.TagStream.Position = StartOffset + 72; int Count = br.ReadInt32(); if (Count > 0) { int Offset = br.ReadInt32(); Resources = new Resource[Count]; for (int i = 0; i < Count; i++) { tag.TagStream.Position = Offset + (i * Resource.Size); Resources[i] = new Resource(tag.TagStream); } } if (Globals.IsExternalResource(RawOffset)) { return; } tag.ResourceStream.Position = tag.ResourceInformation[RawOffset].Address; mesh = new Mesh(tag.ResourceStream, Resources, this, boundingBox); Microsoft.Xna.Framework.Vector3[] points = new Microsoft.Xna.Framework.Vector3[mesh.Vertices.Length]; for (int i = 0; i < points.Length; i++) points[i] = mesh.Vertices[i].Position; BoundingBox = Microsoft.Xna.Framework.BoundingBox.CreateFromPoints(points); }
public byte[] Serialize(Tag tag, CompressionInfo boundingBox) { RawOffset = tag.AddRaw(mesh.Serialize(this, boundingBox, out Resources)); MemoryStream stream = new MemoryStream(Size); BinaryWriter bw = new BinaryWriter(stream); bw.Write(buffer); stream.Seek(0, SeekOrigin.Begin); VertexCount = (short)mesh.Vertices.Length; TriangleCount = (short)(mesh.Indices.Length - 2); VertexType = VertexType.Rigid; CompressionFlags = Compression.Position | Compression.Texcoord; bw.Write((int)VertexType); bw.Write(VertexCount); bw.Write(TriangleCount); stream.Position = 26; bw.Write((int)CompressionFlags); stream.Position = 56; bw.Write(RawOffset);//* bw.Write(0);//* bw.Write(RawHeaderSize); bw.Write(RawDataSize); if (!tag.TagReferences.Contains(tag.Filename)) { tag.TagReferences.Add(tag.Filename); } bw.Write(tag.TagReferences.IndexOf(tag.Filename)); bw.Close(); return stream.GetBuffer(); }
/// <summary> /// Creates a new mesh with enough space to hold the a number of primitives using the specified layout. All indices /// will be part of a single sub-mesh. /// </summary> /// <param name="numVertices">Number of vertices in the mesh.</param> /// <param name="numIndices">Number of indices in the mesh. </param> /// <param name="topology">Determines how should the provided indices be interpreted by the pipeline. Default option /// is a triangle list, where three indices represent a single triangle.</param> /// <param name="usage">Optimizes performance depending on planned usage of the mesh.</param> /// <param name="vertex">Controls how are vertices organized in the vertex buffer and what data they contain.</param> /// <param name="index">Size of indices, use smaller size for better performance, however be careful not to go over /// the number of vertices limited by the size.</param> public Mesh(int numVertices, int numIndices, MeshTopology topology = MeshTopology.TriangleList, MeshUsage usage = MeshUsage.Default, VertexType vertex = VertexType.Position, IndexType index = IndexType.Index32) { SubMesh[] subMeshes = {new SubMesh(0, numIndices, topology)}; Internal_CreateInstance(this, numVertices, numIndices, subMeshes, usage, vertex, index); }
/// <summary> /// Converts a new (1.235640+) vertex shader to one compatible with the 1.106708 pipeline. /// Note that this requires that models have binormals set so that X = Position.W and Y = Tangent.W. /// </summary> /// <param name="shaderData">The shader bytecode to convert.</param> /// <param name="mode">The drawing mode.</param> /// <param name="type">The vertex type.</param> /// <returns>The new bytecode, or <c>null</c> if conversion failed.</returns> public static byte[] ConvertNewVertexShaderToOld(byte[] shaderData, int mode, VertexType type) { // Only applies to world, rigid, skinned, and dual quat if (type != VertexType.World && type != VertexType.Rigid && type != VertexType.Skinned && type != VertexType.DualQuat) return shaderData; // Disassemble the shader var disassembly = ShaderCompiler.Disassemble(shaderData); if (disassembly == null) return null; var lines = disassembly.Split('\n').ToList(); // So, the reason that new vertex shaders don't work in 1.106708 // is because vertex declarations changed. For world, rigid, and // skinned meshes, the normal and binormal components were removed, // and the position and tangent vectors were extended to be 4D. // (The W components are used for various things.) To convert a new // vertex shader to use the old declaration format, we need to do // the following: // // 1. Add an input declaration for the binormal, so we can pull the // position.W and tangent.W values from it (assuming they're // stored that way in the model). // // 2. Remap the W component of the position to the X component of // the binormal. (The W component will never be used alongside // the other position components because it's technically // completely separate.) // // 3. The tangent will be unpacked by using a "mad" instruction. // However, in 1.106708, the tangent isn't packed to begin with. // So, we look for an instruction of the form // // mad [register], v[tangent], [constant], [constant] // // and replace it with instructions to load the components, // with the W component of the tangent in the Y component of the // binormal: // // mov [register].xyz, v[tangent] // mov [register].w, v[binormal].y // // 4. Insert code to handle v_squish_params and v_mesh_squished. // This is mainly needed for first-person models. // // 5. For albedo shaders only, o2 needs to be made 4D and the W // component must be set to the W component of the position so // that the pixel shader can pass it through to an output. This // appears to be necessary for objects to receive shadows. // // 6. For default shaders only, a texcoord1 output has to be added // for storing the W component of the position. This means that // the other texcoord outputs need to be remapped. var addedDeclarations = false; var fixedTangent = false; var lastInput = -1; var tangentRegister = -1; var binormalRegister = -1; var storedZ = false; var storedW = false; var addedSquishParams = false; string squishConstant1 = null; string squishConstant2 = null; var needSquishCheck = false; var wOut = -1; for (var i = 0; i < lines.Count; i++) { if (lines[i].StartsWith("//")) continue; // Find the tangent declaration and keep track of the highest input register var match = Regex.Match(lines[i], @"dcl_(\S+) v(\d+)"); if (match.Success) { var name = match.Groups[1].Value; var register = int.Parse(match.Groups[2].Value); if (name == "tangent") tangentRegister = register; lastInput = Math.Max(lastInput, register); } if (!addedDeclarations) { // Once the first output is found, add a definition for the binormal input before it match = Regex.Match(lines[i], @"dcl_(\S+) o\d+"); if (match.Success) { binormalRegister = lastInput + 1; lines.Insert(i++, string.Format(" dcl_binormal v{0}", binormalRegister)); addedDeclarations = true; continue; } } if (!fixedTangent && tangentRegister >= 0 && binormalRegister >= 0) { // Adjust tangent unpacking match = Regex.Match(lines[i], @"mad r(\d+), v" + tangentRegister); if (match.Success) { var index = int.Parse(match.Groups[1].Value); lines[i++] = string.Format(" mov r{0}.xyz, v{1}", index, tangentRegister); lines.Insert(i, string.Format(" mov r{0}.w, v{1}.y", index, binormalRegister)); fixedTangent = true; continue; } } // When the output Z is set, store it to r31.z instead (for v_squish_params) match = Regex.Match(lines[i], @"\S+ (o0)\.z"); if (match.Success) { var group = match.Groups[1]; lines[i] = lines[i].Remove(group.Index, group.Length).Insert(group.Index, "r31"); storedZ = true; } // When the output W is set, store it to r30.w instead (for v_squish_params) match = Regex.Match(lines[i], @"\S+ (o0)\.w"); if (match.Success) { var group = match.Groups[1]; lines[i] = lines[i].Remove(group.Index, group.Length).Insert(group.Index, "r30"); storedW = true; } // If b8 (v_mesh_squished) is checked, we need to remove most // of it and transform the previous instruction into a store to // r31.z (for the v_squish_params fix later on). match = Regex.Match(lines[i], @"if b8"); if (match.Success) { // Check that the previous instruction stores to a register match = Regex.Match(lines[i - 1], @"\S+ (r\d+\..),"); if (match.Success) { // Get squish constant 1 var constMatch = Regex.Match(lines[i + 1], @"mov r\d+\.., (c\d+\..)"); if (constMatch.Success) squishConstant1 = constMatch.Groups[1].Value; // Get squish constant 2 constMatch = Regex.Match(lines[i + 3], @"mov r\d+\.., (c\d+\..)"); if (constMatch.Success) squishConstant2 = constMatch.Groups[1].Value; if (squishConstant1 != null && squishConstant2 != null) { // Remove the if block lines.RemoveRange(i--, 6); // Transform the previous instruction var group = match.Groups[1]; lines[i] = lines[i].Remove(group.Index, group.Length).Insert(group.Index, "r31.z"); needSquishCheck = true; storedZ = true; } } } // v_squish_params fix if (storedZ && storedW && !addedSquishParams) { lines.Insert(++i, " mad r30.x, c250.x, r30.w, -c250.y\n" + " mad r30.x, r30.x, c250.z, -r31.z"); if (needSquishCheck) { // Check v_mesh_squished lines.Insert(++i, string.Format(" mad r31.z, c250.w, r30.x, r31.z\n" + " if b8\n" + " mov r30.x, {0}\n" + " else\n" + " mov r30.x, {1}\n" + " endif\n" + " add o0.z, -r30.x, r31.z", squishConstant1, squishConstant2)); } else { lines.Insert(++i, " mad o0.z, c250.w, r30.x, r31.z"); } lines.Insert(++i, " mov o0.w, r30.w"); // Needed for shadow receiving if (wOut >= 0) { if (mode == 0) lines.Insert(++i, string.Format(" mov o{0}.x, r30.w", wOut)); else if (mode == 1) lines.Insert(++i, string.Format(" mov o{0}.w, r30.w", wOut)); } addedSquishParams = true; continue; } if (mode == 0) { // Default-only: add a texcoord1 output and remap input registers match = Regex.Match(lines[i], @"dcl_texcoord(\d*) o(\d+)"); if (match.Success) { var texGroup = match.Groups[1]; var outGroup = match.Groups[2]; var outIndex = int.Parse(outGroup.Value); if (texGroup.Length == 0) { wOut = outIndex + 1; lines.Insert(++i, string.Format(" dcl_texcoord1 o{0}.x", outIndex + 1)); continue; } var texIndex = int.Parse(texGroup.Value); lines[i] = lines[i].Remove(texGroup.Index, texGroup.Length).Insert(texGroup.Index, (texIndex + 1).ToString()); lines[i] = lines[i].Remove(outGroup.Index, outGroup.Length).Insert(outGroup.Index, (outIndex + 1).ToString()); continue; } if (wOut >= 0) { foreach (Match m in Regex.Matches(lines[i], @" o(\d+)")) { var group = m.Groups[1]; var index = int.Parse(group.Value); if (index < wOut) continue; index++; lines[i] = lines[i].Remove(group.Index, group.Length).Insert(group.Index, index.ToString()); } } } // Albedo-only: make o2 be 4D if (mode == 1) { match = Regex.Match(lines[i], @"dcl_texcoord1 o2\.xyz"); if (match.Success) { wOut = 2; lines[i] = lines[i].Remove(match.Index, match.Length).Insert(match.Index, "dcl_texcoord1 o2"); continue; } } if (binormalRegister >= 0) { // Change the source of the position W component lines[i] = lines[i].Replace("v0.w", string.Format("v{0}.x", binormalRegister)); } } // Reassemble the shader var newShader = string.Join("\n", lines); string errors; return ShaderCompiler.Assemble(newShader, out errors); }
/// <summary> /// Initializes a new instance of the <see cref="Vertex" /> class. /// </summary> /// <param name="x">The x coordinate of the vertex.</param> /// <param name="y">The y coordinate of the vertex.</param> /// <param name="mark">The boundary mark.</param> public Vertex(double x, double y, int mark) : base(x, y, mark) { this.type = VertexType.InputVertex; }
public MeshBuffer(VertexType type) : this(MeshBuffer_Create((int)type)) { }
private static extern void Internal_CreateInstance(Mesh instance, int numVertices, int numIndices, SubMesh[] subMeshes, MeshUsage usage, VertexType vertex, IndexType index);