示例#1
0
 public void UpdateInstanceTexture()
 {
     if (m_instance_texture == null)
     {
         m_instance_texture            = new RenderTexture(MPWorld.DataTextureWidth, MPWorld.DataTextureHeight, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Default);
         m_instance_texture.filterMode = FilterMode.Point;
         m_instance_texture.Create();
     }
     if (m_texture_needs_update)
     {
         m_texture_needs_update = false;
         MPAPI.mpUpdateDataTexture(GetContext(), m_instance_texture.GetNativeTexturePtr(), m_instance_texture.width, m_instance_texture.height);
     }
 }
示例#2
0
 static void ImmediateUpdate()
 {
     foreach (MPWorld w in s_instances)
     {
         w.UpdateKernelParams();
     }
     UpdateMPObjects();
     foreach (MPWorld w in s_instances)
     {
         MPAPI.mpUpdate(w.GetContext(), Time.deltaTime);
         s_current = w;
         MPAPI.mpCallHandlers(w.GetContext());
         MPAPI.mpClearCollidersAndForces(w.GetContext());
         w.CallUpdateRoutines();
         s_current = null;
     }
 }
示例#3
0
        public static void AddRadialSphereForce(MPWorld world, Vector3 pos, float radius, float strength)
        {
            Matrix4x4         mat = Matrix4x4.TRS(pos, Quaternion.identity, Vector3.one * radius);
            MPForceProperties p   = new MPForceProperties();

            p.shape_type      = MPForceShape.Sphere;
            p.dir_type        = MPForceDirection.Radial;
            p.center          = pos;
            p.strength_near   = strength;
            p.strength_far    = 0.0f;
            p.attenuation_exp = 0.5f;
            p.range_inner     = 0.0f;
            p.range_outer     = radius;
            world.AddOneTimeAction(() =>
            {
                MPAPI.mpAddForce(world.GetContext(), ref p, ref mat);
            });
        }
示例#4
0
        public void MPUpdate()
        {
            if (m_emit_count_prev != m_emit_count)
            {
                m_emit_count_prev = m_emit_count;
                m_total_emit      = Mathf.FloorToInt(m_local_time * m_emit_count);
            }
            m_local_time += Time.deltaTime;
            int emit_total      = Mathf.FloorToInt(m_local_time * m_emit_count);
            int emit_this_frame = emit_total - m_total_emit;

            if (emit_this_frame == 0)
            {
                return;
            }
            m_total_emit = emit_total;

            m_params.velocity = m_velosity_base;
            m_params.velocity_random_diffuse = m_velosity_random_diffuse;
            m_params.lifetime = m_lifetime;
            m_params.lifetime_random_diffuse = m_lifetime_random_diffuse;
            m_params.userdata = m_userdata;
            m_params.handler  = m_spawn_handler;
            Matrix4x4 mat = transform.localToWorldMatrix;

            switch (m_shape)
            {
            case Shape.Sphere:
                EachTargets((w) =>
                {
                    MPAPI.mpScatterParticlesSphereTransform(w.GetContext(), ref mat, emit_this_frame, ref m_params);
                });
                break;

            case Shape.Box:
                EachTargets((w) =>
                {
                    MPAPI.mpScatterParticlesBoxTransform(w.GetContext(), ref mat, emit_this_frame, ref m_params);
                });
                break;
            }
        }
示例#5
0
        public override unsafe void Capture()
        {
            var target    = GetComponent <MPWorld>();
            var ctx       = target.GetContext();
            var num       = MPAPI.mpGetNumParticles(ctx);
            var particles = MPAPI.mpGetParticles(ctx);

            var positions = new Vector3[num];
            var t         = GetComponent <Transform>().worldToLocalMatrix;

            for (int i = 0; i < num; ++i)
            {
                positions[i] = t * new Vector4(particles[i].position.x, particles[i].position.y, particles[i].position.z, 1.0f);
            }

            var data = new aeAPI.aePointsSampleData();

            data.count     = num;
            data.positions = Marshal.UnsafeAddrOfPinnedArrayElement(positions, 0);
            aeAPI.aePointsWriteSample(m_abc, ref data);
        }
示例#6
0
        public void MPUpdate()
        {
            m_mpprops.dir_type        = m_direction_type;
            m_mpprops.shape_type      = m_shape_type;
            m_mpprops.strength_near   = m_strength_near;
            m_mpprops.strength_far    = m_strength_far;
            m_mpprops.rcp_range       = 1.0f / (m_strength_far - m_strength_near);
            m_mpprops.range_inner     = m_range_inner;
            m_mpprops.range_outer     = m_range_outer;
            m_mpprops.attenuation_exp = m_attenuation_exp;
            m_mpprops.random_seed     = m_random_seed;
            m_mpprops.random_diffuse  = m_random_diffuse;
            m_mpprops.direction       = m_direction;
            m_mpprops.center          = transform.position;
            m_mpprops.rcp_cellsize    = new Vector3(1.0f / m_cellsize.x, 1.0f / m_cellsize.y, 1.0f / m_cellsize.z);
            Matrix4x4 mat = transform.localToWorldMatrix;

            EachTargets((w) =>
            {
                MPAPI.mpAddForce(w.GetContext(), ref m_mpprops, ref mat);
            });
        }
示例#7
0
 void Awake()
 {
     m_context = MPAPI.mpCreateContext();
 }
示例#8
0
        MPWorld()
        {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            MPAPI.mphInitialize();
#endif
        }