示例#1
0
        private void ProcessMouseEnter(int instanceIndex)
        {
            MainDXViewportView.Cursor = Cursors.Hand;

            // Change the selected instance color to yellow and increase its size by 2
            // Get the index of selected instance we need the bounds of hit object
            UpdateSelectedInstance(instanceIndex);

            // After instance data is changed we need to call Update method
            _instancedMeshGeometryVisual3D.Update();
        }
示例#2
0
        private void SelectInstance(int instanceIndex)
        {
            if (_selectedInstanceIndex == instanceIndex)
            {
                return; // Already selected
            }
            if (_selectedInstanceIndex != -1)
            {
                DeselectInstance();
            }

            _savedInstanceColor = _instancedMeshGeometryVisual3D.InstancesData[instanceIndex].DiffuseColor;

            _instancedMeshGeometryVisual3D.InstancesData[instanceIndex].DiffuseColor = _selectedColor;
            _instancedMeshGeometryVisual3D.Update(instanceIndex, 1, updateBounds: false);

            _selectedInstanceIndex = instanceIndex;
        }
        private void ChangeInstanceColor(int instanceIndex, System.Windows.Media.Color color)
        {
            if (_selectedInstanceIndex == -1)
            {
                return;
            }

            _instancedMeshGeometryVisual3D.InstancesData[instanceIndex].DiffuseColor = color.ToColor4();
            _instancedMeshGeometryVisual3D.Update(instanceIndex, 1, updateBounds: false);
        }
        private void ChangeAlphaColor(int startIndex, int count, float newAlpha)
        {
            var instancedData = _instancedMeshGeometryVisual3D.InstancesData;

            int endIndex = startIndex + count;

            for (int i = startIndex; i < endIndex; i++)
            {
                var color = instancedData[i].DiffuseColor;
                instancedData[i].DiffuseColor = new Color4(color.Red, color.Green, color.Blue, newAlpha);
            }

            // When only some instances data are changed, then provide startIndex and count to Update method.
            _instancedMeshGeometryVisual3D.Update(startIndex, count, updateBounds: false); // If actual bounds are slightly smaller, then this is not a problem, so preserve the bounds
        }
示例#5
0
        private void ChangeRenderingType()
        {
            if (MainDXViewportView.DXScene == null)
            {
                return; // Probably WPF 3D rendering
            }
            var color = GetColorFromComboBox(SolidModelColorComboBox);

            if (_currentRenderingType == RenderingTypes.SolidColorEffect)
            {
                MainDXViewportView.DXScene.DefaultRenderObjectsRenderingStep.OverrideEffect = null;
            }


            _currentRenderingType = GetCurrentRenderingType();

            if (_currentRenderingType == RenderingTypes.SolidColorEffect)
            {
                _solidColorEffectWithOutline = new Ab3d.DirectX.Effects.SolidColorEffect
                {
                    Color = color.ToColor4(),
                    OverrideModelColor = true
                };

                _solidColorEffectWithOutline.InitializeResources(MainDXViewportView.DXScene.DXDevice);

                MainDXViewportView.DXScene.DefaultRenderObjectsRenderingStep.OverrideEffect = _solidColorEffectWithOutline;
            }
            else if (_currentRenderingType == RenderingTypes.UseSingleObjectColor)
            {
                // Set IsSolidColorMaterial to render tube instances with solid color without any shading based on lighting
                _instancedMeshGeometryVisual3D.IsSolidColorMaterial = IsSolidColorMaterialCheckBox.IsChecked ?? false;

                var instancesData  = _instancedMeshGeometryVisual3D.InstancesData;
                int instancesCount = instancesData.Length;

                for (var i = 0; i < instancesCount; i++)
                {
                    instancesData[i].DiffuseColor = color.ToColor4();
                }

                _instancedMeshGeometryVisual3D.Update(0, instancesCount, updateBounds: false);
            }
            else
            {
                CreateInstances();
            }
        }
        void ICompositionRenderingSubscriber.OnRendering(EventArgs e)
        {
            double elapsedSeconds = (DateTime.Now - _startTime).TotalSeconds;

            // Update statistics only once per second
            if (DateTime.Now.Second != _lastSecond)
            {
                double averageUpdateTime = _updateDataSamplesCount > 0 ? _totalUpdateDataTime / (double)_updateDataSamplesCount : 0;
                double averageRenderTime = _renderingTimeSamplesCount > 0 ? _totalRenderingTime / (double)_renderingTimeSamplesCount : 0;

                RenderingStatsTextBlock.Text = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                             "Update InstanceData time: {0:#,##0.00} ms;  DXEngine rendering time: {1:#,##0.00} ms",
                                                             averageUpdateTime,
                                                             averageRenderTime);

                _totalUpdateDataTime       = 0;
                _updateDataSamplesCount    = 0;
                _totalRenderingTime        = 0;
                _renderingTimeSamplesCount = 0;
                _framesPerSecond           = 0;

                _lastSecond = DateTime.Now.Second;
            }
            else
            {
                _framesPerSecond++;
            }

            if (!(RunAnimationCheckBox.IsChecked ?? false))
            {
                return;
            }

            double x, y, z;

            x = _sphereStartPosition.X;
            y = _sphereStartPosition.Y;
            z = _sphereStartPosition.Z;

            // Rotate on xz plane
            x += Math.Sin(elapsedSeconds * 3) * _xSize * 0.1;
            z += Math.Cos(elapsedSeconds * 3) * _ySize * 0.1;

            // Rotate on xy plane
            x += Math.Sin(elapsedSeconds) * _xSize * 0.2;
            y += Math.Cos(elapsedSeconds) * 90;

            // Rotate on yz plane
            y += Math.Sin(elapsedSeconds * 5) * 50;
            z += Math.Cos(elapsedSeconds * 0.3) * _ySize * 0.2;


            _sphereTranslate.OffsetX = x;
            _sphereTranslate.OffsetY = y;
            _sphereTranslate.OffsetZ = z;

            _spherePosition = new Vector3((float)x, (float)y, (float)z);

            // After we have a new sphere position, we can update the instances data
            UpdateInstanceData();

            _instancedMeshGeometryVisual3D.Update(0, _instanceData.Length, updateBounds: false);
        }