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); transform.NJRotateY(item.Rotation.Y - 0x5772); transform.NJScale((item.Scale.X), (item.Scale.Y), (item.Scale.Z)); float largestScale = item.Scale.X; if (item.Scale.Y > largestScale) largestScale = item.Scale.Y; if (item.Scale.Z > largestScale) largestScale = item.Scale.Z; BoundingSphere boxSphere = new BoundingSphere() { Center = new Vertex(item.Position.X, item.Position.Y, item.Position.Z), Radius = (1.5f * largestScale) }; RenderInfo outputInfo = new RenderInfo(mesh, 0, transform.Top, material, texture, FillMode.Solid, boxSphere); result.Add(outputInfo); if (item.Selected) { RenderInfo highlightInfo = new RenderInfo(mesh, 0, transform.Top, material, texture, FillMode.WireFrame, boxSphere); result.Add(highlightInfo); } transform.Pop(); return result; }
// TODO: Consider returning IEnumerable<RenderInfo> private RenderInfo[] Render(Device dev, MatrixStack transform, EditorCamera cam) { List<RenderInfo> result = new List<RenderInfo>(); if (!enabled) return result.ToArray(); float dist = cam.Position.Distance(position) * 0.0825f; BoundingSphere gizmoSphere = new BoundingSphere() { Center = new Vertex(position.X, position.Y, position.Z), Radius = (1.0f * Math.Abs(dist)) }; #region Setting Render States dev.SetSamplerState(0, SamplerStageStates.MinFilter, (int)TextureFilter.Point); // no fancy filtering is required because no textures are even being used dev.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.Point); dev.SetSamplerState(0, SamplerStageStates.MipFilter, (int)TextureFilter.Point); dev.SetRenderState(RenderStates.Lighting, true); dev.SetRenderState(RenderStates.SpecularEnable, false); dev.SetRenderState(RenderStates.Ambient, Color.White.ToArgb()); dev.SetRenderState(RenderStates.AlphaBlendEnable, false); dev.SetRenderState(RenderStates.ColorVertex, false); dev.Clear(ClearFlags.ZBuffer, 0, 1, 0); #endregion transform.Push(); transform.TranslateLocal(position.X, position.Y, position.Z); transform.RotateXYZLocal(rotation.X, rotation.Y, rotation.Z); transform.ScaleLocal(Math.Abs(dist), Math.Abs(dist), Math.Abs(dist)); #region Handling Transform Modes switch (mode) { case TransformMode.TRANFORM_MOVE: { RenderInfo xRenderInfo = new RenderInfo(Gizmo.XMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.X_AXIS) ? Gizmo.HighlightMaterial : Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere); result.Add(xRenderInfo); RenderInfo yRenderInfo = new RenderInfo(Gizmo.YMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Y_AXIS) ? Gizmo.HighlightMaterial : Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere); result.Add(yRenderInfo); RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Z_AXIS) ? Gizmo.HighlightMaterial : Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere); result.Add(zRenderInfo); if (!isTransformLocal) // this is such a cop-out. I'll try to find a better solution. { RenderInfo xyRenderInfo = new RenderInfo(Gizmo.XYMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.XY_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere); result.Add(xyRenderInfo); RenderInfo zxRenderInfo = new RenderInfo(Gizmo.ZXMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.XZ_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere); result.Add(zxRenderInfo); RenderInfo zyRenderInfo = new RenderInfo(Gizmo.ZYMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.ZY_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere); result.Add(zyRenderInfo); } } break; case TransformMode.TRANSFORM_ROTATE: { RenderInfo xRenderInfo = new RenderInfo(Gizmo.XRotateMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.X_AXIS) ? Gizmo.HighlightMaterial : Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere); result.Add(xRenderInfo); RenderInfo yRenderInfo = new RenderInfo(Gizmo.YRotateMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Y_AXIS) ? Gizmo.HighlightMaterial : Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere); result.Add(yRenderInfo); RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZRotateMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Z_AXIS) ? Gizmo.HighlightMaterial : Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere); result.Add(zRenderInfo); } break; case TransformMode.NONE: { RenderInfo xRenderInfo = new RenderInfo(Gizmo.XNullMesh, 0, transform.Top, Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere); result.Add(xRenderInfo); RenderInfo yRenderInfo = new RenderInfo(Gizmo.YNullMesh, 0, transform.Top, Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere); result.Add(yRenderInfo); RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZNullMesh, 0, transform.Top, Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere); result.Add(zRenderInfo); } break; case TransformMode.TRANSFORM_SCALE: { RenderInfo xRenderInfo = new RenderInfo(Gizmo.XScaleMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.X_AXIS) ? Gizmo.HighlightMaterial : Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere); result.Add(xRenderInfo); RenderInfo yRenderInfo = new RenderInfo(Gizmo.YScaleMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Y_AXIS) ? Gizmo.HighlightMaterial : Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere); result.Add(yRenderInfo); RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZScaleMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Z_AXIS) ? Gizmo.HighlightMaterial : Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere); result.Add(zRenderInfo); } break; } #endregion transform.Pop(); return result.ToArray(); }
private RenderInfo[] Render(Device dev, MatrixStack transform, EditorCamera cam) { List<RenderInfo> result = new List<RenderInfo>(); if (!enabled) return result.ToArray(); float dist = cam.Position.Distance(affectedPoint.ToVector3()) * 0.0825f; BoundingSphere gizmoSphere = new BoundingSphere() { Center = new Vertex(affectedPoint.X, affectedPoint.Y, affectedPoint.Z), Radius = (1.0f * Math.Abs(dist)) }; #region Setting Render States dev.SetSamplerState(0, SamplerStageStates.MinFilter, (int)TextureFilter.Point); // no fancy filtering is required because no textures are even being used dev.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.Point); dev.SetSamplerState(0, SamplerStageStates.MipFilter, (int)TextureFilter.Point); dev.SetRenderState(RenderStates.Lighting, true); dev.SetRenderState(RenderStates.SpecularEnable, false); dev.SetRenderState(RenderStates.Ambient, Color.White.ToArgb()); dev.SetRenderState(RenderStates.AlphaBlendEnable, false); dev.SetRenderState(RenderStates.ColorVertex, false); dev.Clear(ClearFlags.ZBuffer, 0, 1, 0); #endregion transform.Push(); transform.TranslateLocal(affectedPoint.X, affectedPoint.Y, affectedPoint.Z); if (scaleHandlesToCam) transform.ScaleLocal(Math.Abs(dist), Math.Abs(dist), Math.Abs(dist)); else transform.ScaleLocal(handleSize, handleSize, handleSize); #region Creating Render Info RenderInfo xRenderInfo = new RenderInfo(Gizmo.XMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.X_AXIS) ? Gizmo.HighlightMaterial : Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere); result.Add(xRenderInfo); RenderInfo yRenderInfo = new RenderInfo(Gizmo.YMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Y_AXIS) ? Gizmo.HighlightMaterial : Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere); result.Add(yRenderInfo); RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Z_AXIS) ? Gizmo.HighlightMaterial : Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere); result.Add(zRenderInfo); RenderInfo xyRenderInfo = new RenderInfo(Gizmo.XYMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.XY_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere); result.Add(xyRenderInfo); RenderInfo zxRenderInfo = new RenderInfo(Gizmo.ZXMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.XZ_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere); result.Add(zxRenderInfo); RenderInfo zyRenderInfo = new RenderInfo(Gizmo.ZYMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.ZY_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere); result.Add(zyRenderInfo); #endregion transform.Pop(); return result.ToArray(); }
public void DrawBox(Device d3ddevice, EditorCamera cam) { if (!enabled || !drawCube) return; BoundingSphere gizmoSphere = new BoundingSphere() { Center = new Vertex(affectedPoint.X, affectedPoint.Y, affectedPoint.Z), Radius = handleSize }; MatrixStack transform = new MatrixStack(); transform.Push(); transform.TranslateLocal(affectedPoint.X, affectedPoint.Y, affectedPoint.Z); transform.ScaleLocal(handleSize, handleSize, handleSize); RenderInfo boxRenderInfo = new RenderInfo(Gizmo.BoxMesh, 0, transform.Top, Gizmo.StandardMaterial, BoxTexture, FillMode.Solid, gizmoSphere); RenderInfo.Draw(new List<RenderInfo>() { boxRenderInfo }, d3ddevice, cam); transform.Pop(); }
public override List<RenderInfo> Render(Device dev, EditorCamera camera, MatrixStack transform) { if (!camera.SphereInFrustum(Bounds)) return EmptyRenderInfo; List<RenderInfo> result = new List<RenderInfo>(); transform.Push(); transform.NJTranslate(Position); transform.NJRotateY(Rotation.Y); transform.NJScale((Scale.X), (Scale.Y), (Scale.Z)); RenderInfo outputInfo = new RenderInfo(VolumeMesh, 0, transform.Top, Material, null, FillMode.Solid, Bounds); if (Selected) { NJS_MATERIAL mat = new NJS_MATERIAL { DiffuseColor = Color.White, IgnoreLighting = true, UseAlpha = false }; result.Add(new RenderInfo(VolumeMesh, 0, transform.Top, mat, null, FillMode.WireFrame, Bounds)); } result.Add(outputInfo); transform.Pop(); return result; }
public override List<RenderInfo> Render(Device dev, EditorCamera camera, MatrixStack transform) { if (!camera.SphereInFrustum(Bounds)) return EmptyRenderInfo; List<RenderInfo> result = new List<RenderInfo>(); RenderInfo outputInfo = new RenderInfo(mesh, 0, Matrix.Identity, (Selected) ? SelectedMaterial : UnSelectedMaterial, null, EditorOptions.RenderFillMode, Bounds); result.Add(outputInfo); textSprite.Begin(SpriteFlags.AlphaBlend); Matrix view = camera.ToMatrix(); Matrix projection = Matrix.PerspectiveFovRH(camera.FOV, camera.Aspect, 1, camera.DrawDistance); if (Selected) { for (int vIndx = 0; vIndx < splineData.Path.Count(); vIndx++) { #region Draw Vertex IDs Vector3 screenCoordinates = Vector3.Project(new Vector3(splineData.Path[vIndx].Position.X, splineData.Path[vIndx].Position.Y, splineData.Path[vIndx].Position.Z), dev.Viewport, projection, view, Matrix.Identity); Vector3 altScrCoord = Vector3.Project(new Vector3(splineData.Path[vIndx].Position.X, splineData.Path[vIndx].Position.Y, splineData.Path[vIndx].Position.Z), dev.Viewport, dev.Transform.Projection, dev.Transform.View, Matrix.Identity); EditorOptions.OnscreenFont.DrawText(textSprite, vIndx.ToString(), new Point((int)(screenCoordinates.X), (int)(screenCoordinates.Y)), Color.White); #endregion #region Draw Vertex Handles transform.Push(); transform.Translate(splineData.Path[vIndx].Position.X, splineData.Path[vIndx].Position.Y, splineData.Path[vIndx].Position.Z); result.Add(new RenderInfo(vertexHandleMesh, 0, transform.Top, UnSelectedMaterial, null, FillMode.Solid, new BoundingSphere(splineData.Path[vIndx].Position.X, splineData.Path[vIndx].Position.Y, splineData.Path[vIndx].Position.Z, 1f))); if (vIndx == selectedKnot) result.Add(new RenderInfo(vertexHandleMesh, 0, transform.Top, SelectedMaterial, null, FillMode.WireFrame, new BoundingSphere(splineData.Path[vIndx].Position.X, splineData.Path[vIndx].Position.Y, splineData.Path[vIndx].Position.Z, 1f))); transform.Pop(); #endregion } } textSprite.End(); return result; }