Пример #1
0
        private void toolStripButtonViewShape_Click(object sender, EventArgs e)
        {
            ShapeSelection shapeSelection = new ShapeSelection();
            EmitterShape   currentShape   = particleEffectControl.ParticleEffect.Emitter.Shape;

            shapeSelection.ShapeType   = currentShape.Type;
            shapeSelection.ShapeOffset = currentShape.Offset;
            shapeSelection.ShapeSize   = currentShape.Size;
            shapeSelection.TexturePath = lastTextureMaskPath;
            if (shapeSelection.ShowDialog() == DialogResult.OK)
            {
                EmitterShape shape = new EmitterShape(shapeSelection.ShapeType, shapeSelection.ShapeSize,
                                                      particleEffectControl.ParticleEffect.Position, shapeSelection.ShapeOffset);
                // if it's a mask, construct it
                if (shape.Type == EmitterShapeType.TextureMask)
                {
                    try
                    {
                        lastTextureMaskPath = shapeSelection.TexturePath;
                        Texture2D maskTexture = Texture2D.FromStream(DrawingManager.GraphicsDevice, System.IO.File.OpenRead(shapeSelection.TexturePath));
                        shape.CreateTextureMaskFromTexture2D(maskTexture, shapeSelection.UseFilled, shapeSelection.UseLeft,
                                                             shapeSelection.UseRight, shapeSelection.UseTop, shapeSelection.UseBottom);
                    }
                    catch
                    {
                        MessageBox.Show("Error: " + e.ToString(), "Error while loading texture",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                shape.Initialize();
                particleEffectControl.ParticleEffect.Emitter.Shape = shape;
            }
        }
Пример #2
0
        protected override bool Initialize()
        {
            RemoveInvalidTemplates();

            if (m_templates.Count == 0)
            {
                Debug.LogWarning("Unable to initialize RigidBodyEmitter: 0 valid templates.", this);
                return(false);
            }
            if (EmitterShape == null)
            {
                Debug.LogWarning("Unable to initialize RigidBodyEmitter: Emitter Shape is null.", this);
                return(false);
            }
            if (EmitterShape.GetInitialized <Collide.Shape>() == null)
            {
                Debug.LogWarning($"Unable to initialize RigidBodyEmitter: Emitter Shape {EmitterShape.name} is invalid.", this);
                return(false);
            }
            if (!EmitterShape.IsSensor)
            {
                Debug.LogWarning($"RigidBodyEmitter Emitter Shape isn't a sensor but will be set to sensor by AGX Dynamics.", this);
            }

            Native = new agx.RigidBodyEmitter();
            Native.setEnable(isActiveAndEnabled);
            m_event = new EmitEvent(this);

            NativeDistributionTable = new agx.Emitter.DistributionTable();
            Native.setDistributionTable(NativeDistributionTable);

            m_distributionModels = new List <agx.RigidBodyEmitter.DistributionModel>();
            var msProperties = GetComponent <MergeSplitProperties>()?.GetInitialized <MergeSplitProperties>();

            foreach (var entry in TemplateEntries)
            {
                agx.RigidBody templateInstance = null;
                if (!m_preInitializedTemplates.TryGetValue(entry.RigidBody, out templateInstance))
                {
                    templateInstance = RigidBody.InstantiateTemplate(entry.RigidBody,
                                                                     entry.RigidBody.GetComponentsInChildren <Collide.Shape>());
                }
                if (msProperties != null)
                {
                    msProperties.RegisterNativeAndSynchronize(agxSDK.MergeSplitHandler.getOrCreateProperties(templateInstance));
                }
                var distributionModel = new agx.RigidBodyEmitter.DistributionModel(templateInstance,
                                                                                   entry.ProbabilityWeight);

                NativeDistributionTable.addModel(distributionModel);
                m_distributionModels.Add(distributionModel);

                m_event.MapResource(entry.RigidBody.name,
                                    entry.FindRenderResource());

                // Handling collision group in the template hierarchy.
                // These components aren't instantiated during emit.
                // This enables collision filtering via the CollisionGroupsManager.
                var collisionGroupComponents = entry.RigidBody.GetComponentsInChildren <CollisionGroups>();
                foreach (var collisionGroupComponent in collisionGroupComponents)
                {
                    foreach (var collisionGroupEntry in collisionGroupComponent.Groups)
                    {
                        Native.addCollisionGroup(collisionGroupEntry.Tag.To32BitFnv1aHash());
                    }
                }
            }

            m_preInitializedTemplates.Clear();

            Native.setGeometry(EmitterShape.NativeGeometry);

            GetSimulation().add(Native);
            Simulation.Instance.StepCallbacks.PostStepForward      += SynchronizeVisuals;
            Simulation.Instance.StepCallbacks.SimulationPreCollide += OnSimulationPreCollide;

            return(true);
        }