protected override void DrawOverride(IDeviceContextHolder contextHolder, ICamera camera, SpecialRenderMode mode) { if (mode == SpecialRenderMode.Shadow) { if (_pntgObject == null) { _pntgObject = new TrianglesRenderableObject <InputLayouts.VerticePNTG>("", InputLayouts.VerticePNTG.Convert(OriginalNode.Vertices), Indices); _pntgObject.Draw(contextHolder, camera, SpecialRenderMode.InitializeOnly); _txNormal = contextHolder.Get <INormalsNormalTexturesProvider>().GetTexture(contextHolder, OriginalNode.MaterialId); _txNormalView = _txNormal?.Item1.Resource ?? contextHolder.GetFlatNmTexture(); } if (_materialDepth == null) { return; } _materialDepth.PrepareAo(contextHolder, _txNormalView, _txNormal?.Item2 ?? 1f); _pntgObject.SetBuffers(contextHolder); _materialDepth.SetMatricesAo(ParentMatrix); _materialDepth.DrawAo(contextHolder, Indices.Length); } else { if (mode != SpecialRenderMode.Simple) { return; } if (!_material.Prepare(contextHolder, mode)) { return; } if (_materialDepth != null) { if (!_txAlphaSet) { _txAlphaSet = true; _txAlpha = contextHolder.TryToGet <IAlphaTexturesProvider>()?.GetTexture(contextHolder, OriginalNode.MaterialId); _txAlphaView = _txAlpha?.Item1.Resource; } if (_txAlpha != null) { _materialDepth.PrepareShadow(_txAlphaView, _txAlphaView == null ? -1f : _txAlpha.Item2); } else { _materialDepth.PrepareShadow(null, -1f); } } base.DrawOverride(contextHolder, camera, mode); _material.SetMatrices(ParentMatrix, camera); _material.Draw(contextHolder, Indices.Length, mode); } }
public override void Draw(IDeviceContextHolder holder, ICamera camera, SpecialRenderMode mode, Func <IRenderableObject, bool> filter = null) { if (_dirNode != null && !_dirTargetSet) { _dirTargetSet = true; var model = holder.TryToGet <IKn5Model>(); if (model != null) { _dirTarget = model.GetDummyByName(_dirNode); _dirTarget?.LookAt(this); } } base.Draw(holder, camera, mode, filter); }
public T TryToGet <T>() where T : class { if (typeof(T) == typeof(ITexturesProvider)) { return(_texturesProvider as T); } if (typeof(T) == typeof(SharedMaterials)) { return(_sharedMaterials as T); } if (typeof(T) == typeof(IKn5Model)) { return(_model as T); } return(_mainHolder.TryToGet <T>()); }
public override void Draw(IDeviceContextHolder contextHolder, ICamera camera, SpecialRenderMode mode, Func <IRenderableObject, bool> filter = null) { if (_dirNode != null && !_dirTargetSet) { _dirTargetSet = true; var model = contextHolder.TryToGet <IKn5Model>(); if (model != null) { _dirTarget = model.GetDummyByName(_dirNode); _dirTarget?.LookAt(this); } } base.Draw(contextHolder, camera, mode, filter); if (HighlightDummy && mode == SpecialRenderMode.SimpleTransparent) { _lines.ParentMatrix = Matrix; _lines.Draw(contextHolder, camera, SpecialRenderMode.Simple); } }
public void Draw(IDeviceContextHolder holder, ICamera camera, SpecialRenderMode mode, Func <IRenderableObject, bool> filter = null) { const float arrowSize = 0.08f; const float circleSize = 0.06f; const float boxSize = 0.14f; if (_arrowX == null) { _arrowX = DebugLinesObject.GetLinesArrow(Matrix.Identity, Vector3.UnitX, new Color4(0f, 1f, 0f, 0f), arrowSize); _arrowY = DebugLinesObject.GetLinesArrow(Matrix.Identity, Vector3.UnitY, new Color4(0f, 0f, 1f, 0f), arrowSize); _arrowZ = DebugLinesObject.GetLinesArrow(Matrix.Identity, Vector3.UnitZ, new Color4(0f, 0f, 0f, 1f), arrowSize); if (_rotationAxis.HasFlag(MoveableRotationAxis.X)) { _circleX = DebugLinesObject.GetLinesCircle(Matrix.Identity, Vector3.UnitX, new Color4(0f, 1f, 0f, 0f), radius: circleSize); } if (_rotationAxis.HasFlag(MoveableRotationAxis.Y)) { _circleY = DebugLinesObject.GetLinesCircle(Matrix.Identity, Vector3.UnitY, new Color4(0f, 0f, 1f, 0f), radius: circleSize); } if (_rotationAxis.HasFlag(MoveableRotationAxis.Z)) { _circleZ = DebugLinesObject.GetLinesCircle(Matrix.Identity, Vector3.UnitZ, new Color4(0f, 0f, 0f, 1f), radius: circleSize); } if (_allowScaling) { _scale = DebugLinesObject.GetLinesBox(Matrix.Identity, new Vector3(boxSize), new Color4(0f, 1f, 1f, 0f)); } } var matrix = ParentMatrix.GetTranslationVector().ToFixedSizeMatrix(camera); if (_arrowX.ParentMatrix != matrix) { _arrowX.ParentMatrix = matrix; _arrowY.ParentMatrix = matrix; _arrowZ.ParentMatrix = matrix; _arrowX.UpdateBoundingBox(); _arrowY.UpdateBoundingBox(); _arrowZ.UpdateBoundingBox(); if (_circleX != null) { _circleX.ParentMatrix = matrix; _circleX.UpdateBoundingBox(); } if (_circleY != null) { _circleY.ParentMatrix = matrix; _circleY.UpdateBoundingBox(); } if (_circleZ != null) { _circleZ.ParentMatrix = matrix; _circleZ.UpdateBoundingBox(); } if (_scale != null) { _scale.ParentMatrix = matrix; _scale.UpdateBoundingBox(); } } if (_keepHighlight) { _arrowX.Draw(holder, camera, _arrowHighlighted.X == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline); _arrowY.Draw(holder, camera, _arrowHighlighted.Y == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline); _arrowZ.Draw(holder, camera, _arrowHighlighted.Z == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline); _circleX?.Draw(holder, camera, _circleHighlighted.X == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline); _circleY?.Draw(holder, camera, _circleHighlighted.Y == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline); _circleZ?.Draw(holder, camera, _circleHighlighted.Z == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline); _scale?.Draw(holder, camera, _scaleHighlighted ? SpecialRenderMode.Outline : SpecialRenderMode.Simple); } else { var mousePosition = holder.TryToGet <IMousePositionProvider>()?.GetRelative(); var rayN = mousePosition == null ? null : (camera as CameraBase)?.GetPickingRay(mousePosition.Value, new Vector2(1f, 1f)); if (!rayN.HasValue) { return; } var ray = rayN.Value; _arrowHighlighted = new Vector3( _arrowX.DrawHighlighted(ray, holder, camera) ? 1f : 0f, _arrowY.DrawHighlighted(ray, holder, camera) ? 1f : 0f, _arrowZ.DrawHighlighted(ray, holder, camera) ? 1f : 0f); if (_arrowHighlighted == Vector3.Zero) { _circleHighlighted = new Vector3( _circleX?.DrawHighlighted(ray, holder, camera) ?? false ? 1f : 0f, _circleY?.DrawHighlighted(ray, holder, camera) ?? false ? 1f : 0f, _circleZ?.DrawHighlighted(ray, holder, camera) ?? false ? 1f : 0f); } else { _circleHighlighted = Vector3.Zero; _circleX?.Draw(holder, camera, SpecialRenderMode.Simple); _circleY?.Draw(holder, camera, SpecialRenderMode.Simple); _circleZ?.Draw(holder, camera, SpecialRenderMode.Simple); } if (_arrowHighlighted == Vector3.Zero && _circleHighlighted == Vector3.Zero) { _scaleHighlighted = _scale?.DrawHighlighted(ray, holder, camera) ?? false; } else { _scaleHighlighted = false; _scale?.Draw(holder, camera, SpecialRenderMode.Simple); } } }