示例#1
0
        Mesh LookupOrCreateChildMesh(int childId, double unitScale)
        {
            Mesh mesh;

            childId = Utilities.Clamp(childId, -1, _fbxScene.NumObjects - 1);

            var cacheKey = new KeyValuePair <int, double>(childId, unitScale);

            if (!_cachedChildMeshes.TryGetValue(cacheKey, out mesh))
            {
                _fbxScene.UnitScale = unitScale;
                MeshData meshData = _fbxScene.GetMeshFromChild(childId);
                if (meshData != null)
                {
                    var inputElements = new InputElement[]
                    {
                        new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 0, 0),
                        new InputElement("NORMAL", 0, SharpDX.DXGI.Format.R32G32B32_Float, 16, 0),
                        new InputElement("COLOR", 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 28, 0),
                        new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float, 44, 0),
                        new InputElement("TANGENT", 0, SharpDX.DXGI.Format.R32G32B32_Float, 52, 0),
                        new InputElement("BINORMAL", 0, SharpDX.DXGI.Format.R32G32B32_Float, 64, 0)
                    };

                    const int attributesSize = 76;
                    int       numTriangles   = meshData.Vertices.Length / 3;

                    using (var vertexStream = new DataStream(meshData.DataBytes, true, true))
                    {
                        vertexStream.Write(meshData.Data, 0, meshData.DataBytes);
                        vertexStream.Position = 0;
                        var vertices = new Buffer(D3DDevice.Device, vertexStream, new BufferDescription()
                        {
                            BindFlags      = BindFlags.VertexBuffer,
                            CpuAccessFlags = CpuAccessFlags.None,
                            OptionFlags    = ResourceOptionFlags.None,
                            SizeInBytes    = meshData.DataBytes,
                            Usage          = ResourceUsage.Default
                        });

                        mesh = new Mesh()
                        {
                            InputElements = inputElements, Vertices = vertices, NumTriangles = numTriangles, AttributesSize = attributesSize
                        };
                        _cachedChildMeshes[cacheKey] = mesh;
                        Logger.Debug("Created child mesh (childId: {0}, scale: {1}, vertices: {2}, triangles: {3})", childId, unitScale, meshData.Vertices.Length, numTriangles);
                    }
                }
            }
            return(mesh);
        }
示例#2
0
        public FullScreenView(RenderViewConfiguration renderConfig)
        {
            _renderConfig = renderConfig;
            App.Current.MainWindow.Hide();
            System.Windows.Forms.Cursor.Hide();

            KeyDown          += KeyDownHandler;
            KeyUp            += KeyUpHandler;
            MouseDown        += MouseDownHandler;
            MouseUp          += MouseUpHandler;
            MouseWheel       += MouseWheelHandler;
            MouseMove        += MouseMoveHandler;
            MouseDoubleClick += MouseDoubleClickHandler;
            CurrentTime       = 0;
            PlaySpeed         = 0;
            FormBorderStyle   = FormBorderStyle.None;


            var settings = new ContextSettings();

            settings.DisplayMode = new SharpDX.Direct3D9.DisplayMode()
            {
                Width       = (int)App.Current.ProjectSettings.GetOrSetDefault("Tooll.FullScreen.Resolution.Width", 1920),
                Height      = (int)App.Current.ProjectSettings.GetOrSetDefault("Tooll.FullScreen.Resolution.Height", 1080),
                RefreshRate = 60,
                Format      = SharpDX.Direct3D9.Format.A8R8G8B8
            };
            settings.AspectRatio = settings.DisplayMode.AspectRatio;

            var displayNumber = int.Parse(App.Current.ProjectSettings.GetOrSetDefault("Tooll.FullScreen.DisplayNumber", "1"));

            displayNumber = Utilities.Clamp(displayNumber, 0, Screen.AllScreens.GetLength(0) - 1);
            Location      = Screen.AllScreens[displayNumber].WorkingArea.Location;

            CurrentTime = App.Current.Model.GlobalTime;
            PlaySpeed   = App.Current.MainWindow.CompositionView.PlaySpeed;
            App.Current.MainWindow.CompositionView.PlaySpeed = 0;

            Run(settings);

            App.Current.Model.GlobalTime = CurrentTime;
            App.Current.MainWindow.CompositionView.PlaySpeed = PlaySpeed;

            App.Current.MainWindow.Show();
            App.Current.MainWindow.Activate();
            App.Current.MainWindow.InvalidateVisual();
            App.Current.MainWindow.XCompositionViewDock.Focus();
            System.Windows.Forms.Cursor.Show();
        }
示例#3
0
        public double GetValue(double time)
        {
            if (_lastTime == time)
            {
                return(_value);
            }
            _lastTime = time;


            // ignore first call
            if (_time == 0)
            {
                _time = time;
                return(_value);
            }

            double timeFragment = time - _time;

            timeFragment = Math.Max(-MAX_TIME_FRAGMENT, Math.Min(timeFragment, MAX_TIME_FRAGMENT));
            //if (timeFragment > MAX_TIME_FRAGMENT)
            //    timeFragment = MAX_TIME_FRAGMENT;


            _time = time;

            if (!_running)
            {
                return(_value);
            }

            // calculate optimal speed
            double distanceBrake = _speed * _speed / Acceleration;
            double distance      = _valueEnd - _value;

            if (Math.Abs(distance) < Precision)
            {
                // and abs(_speed) * _acceleration * 2.4  < _delta:
                _speed   = 0.0;
                _value   = _valueEnd;
                _running = false;
            }
            else if (distance < 0)
            {
                // wrong direction
                if (_speed > 0)
                {
                    _speed -= Acceleration * timeFragment;
                }
                // accelerate neg
                else if (Math.Abs(distance) > distanceBrake)
                {
                    if (Math.Abs(_speed) < _maxSpeed)
                    {
                        _speed = Utilities.Clamp(_speed - Acceleration * timeFragment * 0.8, -_maxSpeed, 0.0);
                    }
                    else
                    {
                        _speed *= 0.99;
                    }
                }

                //
                else
                {
                    if (Math.Abs(distance) < Precision * 5.0 && Math.Abs(Acceleration) < Precision)
                    {
                        Acceleration *= 1.0 - (Math.Abs(distance) - Precision * 5.0) / 50.0;
                    }
                    _speed += Acceleration * timeFragment;
                }
            }
            else if (distance > 0)
            {
                // wrong direction
                if (_speed < 0)
                {
                    _speed += Acceleration * timeFragment;
                }

                // accelerate neg
                else if (Math.Abs(distance) > distanceBrake)
                {
                    if (Math.Abs(_speed) < _maxSpeed)
                    {
                        _speed = Utilities.Clamp(_speed + Acceleration * timeFragment * 0.8, 0.0, _maxSpeed);
                    }
                    else
                    {
                        _speed *= 0.99;
                    }
                }
                // deccalerate neg
                else
                {
                    if (Math.Abs(distance) < Precision * 5.0 && Math.Abs(Acceleration) < Precision)
                    {
                        Acceleration *= 1.0 - (Math.Abs(distance) - Precision * 5.0) / 50.0;
                    }

                    _speed -= Acceleration * timeFragment;
                }
            }

            //if _debug:
            //        note("value=%4.3f\tspeed=%4.3f\tdistance=%4.3f\tbrake=%4.3f\tdt=%4.3f\tvalueEnd=%4.3f  maxSpeed=%4.3f" % (_value, _speed, distance, distanceBrake, timeFragment, _valueEnd, _maxSpeed))
            _value += _speed * timeFragment;

            if (!Double.IsNaN(_min) && _value < _min)
            {
                _speed *= -_borderFriction;
                _value  = _min + _borderFriction * (_value - _min);
                if (_valueEnd > _min)
                {
                    _valueEnd = _min;
                }
            }

            if (!Double.IsNaN(_max) && _value > _max)
            {
                _speed *= -_borderFriction;
                _value  = _max - _borderFriction * (_value - _max);
                if (_valueEnd < _max)
                {
                    _valueEnd = _max;
                }
            }
            _lastTime = time;
            return(_value);
        }