public override List <RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform) { List <RenderInfo> result = new List <RenderInfo>(); transform.Push(); transform.NJTranslate(item.Position); int x = item.Rotation.X; int y = item.Rotation.Y; if (!item.Scale.IsEmpty) { (item.Position - item.Scale).GetRotation(out x, out y); } transform.NJRotateX(x); transform.NJRotateY(y); transform.NJRotateZ(item.Rotation.Z); result.AddRange(model.DrawModelTree(dev.GetRenderState <FillMode>(RenderState.FillMode), transform, ObjectHelper.GetTextures("OBJ_REGULAR"), meshes)); if (item.Selected) { result.AddRange(model.DrawModelTreeInvert(transform, meshes)); } transform.Pop(); if (item.Selected) { FVF_PositionColored[] verts = new FVF_PositionColored[2]; verts[0] = new FVF_PositionColored(item.Position.ToVector3(), System.Drawing.Color.Yellow); verts[1] = new FVF_PositionColored(item.Scale.ToVector3(), System.Drawing.Color.Yellow); dev.VertexFormat = FVF_PositionColored.Format; dev.DrawUserPrimitives(PrimitiveType.LineList, 1, verts); } return(result); }
public void RebuildMesh(Device device) { List <FVF_PositionColored> vertList = new List <FVF_PositionColored>(); List <short> faceIndexList = new List <short>(); Vector3 up = new Vector3(0, 1, 0); #region Segment vert/face creation short highestFaceIndex = 0; for (int i = 0; i < splineData.Path.Count - 1; i++) // don't process the last knot { Vector3 thisKnot = new Vector3(splineData.Path[i].Position.X, splineData.Path[i].Position.Y, splineData.Path[i].Position.Z); Vector3 nextKnot = new Vector3(splineData.Path[i + 1].Position.X, splineData.Path[i + 1].Position.Y, splineData.Path[i + 1].Position.Z); Vector3 directionToNextKnot = Vector3.Normalize(nextKnot - thisKnot); Vector3 perpendicularDirection = Vector3.Cross(directionToNextKnot, up); // verts for knot 1 FVF_PositionColored vert1_1; // top vert 1 (0) FVF_PositionColored vert1_2; // top vert 2 (1) FVF_PositionColored vert1_3; // bottom vert 1 (2) FVF_PositionColored vert1_4; // bottom vert 2 (3) // verts for knot 2 FVF_PositionColored vert2_1; // top vert 1 (4) FVF_PositionColored vert2_2; // top vert 2 (5) FVF_PositionColored vert2_3; // bottom vert 1 (6) FVF_PositionColored vert2_4; // bottom vert 2 (7) // move top verts vert1_1 = new FVF_PositionColored((thisKnot + (perpendicularDirection * splineMeshRadius)), Color.White); vert1_2 = new FVF_PositionColored((thisKnot + (perpendicularDirection * (splineMeshRadius * -1))), Color.White); vert2_1 = new FVF_PositionColored((nextKnot + (perpendicularDirection * splineMeshRadius)), Color.White); vert2_2 = new FVF_PositionColored((nextKnot + (perpendicularDirection * (splineMeshRadius * -1))), Color.White); // move bottom verts vert1_3 = new FVF_PositionColored(vert1_1.Position - (up * splineMeshRadius), Color.White); vert1_4 = new FVF_PositionColored(vert1_2.Position - (up * splineMeshRadius), Color.White); vert2_3 = new FVF_PositionColored(vert2_1.Position - (up * splineMeshRadius), Color.White); vert2_4 = new FVF_PositionColored(vert2_2.Position - (up * splineMeshRadius), Color.White); List <short> thisKnotFaceIndexes = new List <short> { // far side 4, 0, 6, 6, 2, 0, // bottom 6, 2, 3, 3, 7, 6, // our side 7, 3, 1, 7, 5, 1, // top 1, 5, 4, 4, 0, 1 }; for (int faceIndx = 0; faceIndx < thisKnotFaceIndexes.Count(); faceIndx++) { thisKnotFaceIndexes[faceIndx] += (short)vertList.Count(); // this is the wrong approach because it's the verts we're indexing, not the faces! if (thisKnotFaceIndexes[faceIndx] > highestFaceIndex) { highestFaceIndex = thisKnotFaceIndexes[faceIndx]; } } // add verts to vert list and faces to face list vertList.Add(vert1_1); vertList.Add(vert1_2); vertList.Add(vert1_3); vertList.Add(vert1_4); vertList.Add(vert2_1); vertList.Add(vert2_2); vertList.Add(vert2_3); vertList.Add(vert2_4); faceIndexList.AddRange(thisKnotFaceIndexes); } #endregion vertices = vertList.ToArray(); faceIndeces = faceIndexList.ToArray(); // build bounding sphere bounds = SharpDX.BoundingSphere.FromPoints(vertices.Select(a => a.Position).ToArray()).ToSAModel(); // build actual mesh from face index array and vbuf mesh = new Mesh <FVF_PositionColored>(vertices, new short[][] { faceIndeces }); // create a vertexHandle if (vertexHandleMesh == null) { vertexHandleMesh = Mesh.Box(1, 1, 1); } textSprite = new Sprite(device); // todo: do we really have to create this so often? Look into storing a cache list statically? }