Exemple #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Direct Simulation, no ClientGraphics involved only moving occurrences in assembly context
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private void Run()
        {
            Initialize();

            System.Windows.Forms.Application.AddMessageFilter(new MsgFilter());

            Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

            AssemblyDocument            doc     = InvApp.ActiveDocument as AssemblyDocument;
            AssemblyComponentDefinition compDef = doc.ComponentDefinition;

            Inventor.View view = InvApp.ActiveView;

            InvApp.UserInterfaceManager.UserInteractionDisabled = true;

            Transaction Tx = InvApp.TransactionManager.StartGlobalTransaction(doc as _Document, "Simulation");

            ObjectCollection colOccurrences     = InvApp.TransientObjects.CreateObjectCollection(null);
            ObjectCollection colTransformations = InvApp.TransientObjects.CreateObjectCollection(null);

            foreach (ComponentOccurrence occurrence in compDef.Occurrences)
            {
                colOccurrences.Add(occurrence);
                colTransformations.Add(occurrence.Transformation);
            }

            AdnTimer timer = new AdnTimer();

            double[] transfo = new double[16];

            _bActive = true;

            while (_bActive)
            {
                System.Windows.Forms.Application.DoEvents();

                double dT = timer.ElapsedSeconds;

                _dynamicsWorld.StepSimulation(dT, 10);

                int idx = 1;

                foreach (RigidBody body in _mapOccurrencesToBodies.Values)
                {
                    body.GetWorldTransform(ref transfo);

                    Matrix matrix = colTransformations[idx] as Matrix;

                    matrix.PutMatrixData(ref transfo);

                    ++idx;
                }

                compDef.TransformOccurrences(colOccurrences, colTransformations, true);

                view.Update();

                ComputeFrameRate(dT);
            }

            _dynamicsWorld.CleanUp();

            Tx.End();

            InvApp.UserInterfaceManager.UserInteractionDisabled = false;
        }