/*
-----------------------------------------------------------------------------
This source file is part of OpenSpace3D
For the latest info, see http://www.openspace3d.com
Copyright (c) 2012 I-maginer
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt
-----------------------------------------------------------------------------
*/
/*
Version : 1.0
First version : 05/08/2010
Author : Bourineau Bastien
*/
struct PlugParticle = [
PPART_inst : PInstance,
PPART_object : SO3_OBJECT,
PPART_fSpeed : F
]mkPlugParticle;;
/*! \brief Callback on instance destruction
*
* Prototype: fun [PInstance PlugParticle] I
*
* \param PInstance : destroyed plugIT instance
* \param PlugParticle : particle instance structure
*
* \return I : 0
**/
fun deleteOb(inst, ppartstr)=
SO3ParticleSystemSetEnable ppartstr.PPART_object 0;
SO3ParticleSystemClear ppartstr.PPART_object;
0;;
/*! \brief Callback on "Play" dms action
*
* Play the particle system
*
* Prototype: fun [PInstance DMI S S I PlugParticle] I
*
* \param PInstance : plugIT instance
* \param DMI : DMS module who call the action (not used)
* \param S : name of the launched action
* \param S : data posted in DMS action link
* \param I : reply flag (not used)
* \param PlugParticle : particle instance structure
*
* \return I : 0
**/
fun cbPlayParticle(inst, from, action, param, rep, ppartstr) =
SO3ParticleSystemSetSpeedFactor ppartstr.PPART_object ppartstr.PPART_fSpeed;
SO3ParticleSystemSetEnable ppartstr.PPART_object 1;
0;;
/*! \brief Callback on "Pause" dms action
*
* Pause the particle system
*
* Prototype: fun [PInstance DMI S S I PlugParticle] I
*
* \param PInstance : plugIT instance
* \param DMI : DMS module who call the action (not used)
* \param S : name of the launched action
* \param S : data posted in DMS action link
* \param I : reply flag (not used)
* \param PlugParticle : particle instance structure
*
* \return I : 0
**/
fun cbPauseParticle(inst, from, action, param, rep, ppartstr) =
let if (atoi param) != nil then (atoi param) else 1 -> pause in
SO3ParticleSystemSetPause ppartstr.PPART_object pause;
0;;
/*! \brief Callback on "Stop" dms action
*
* Stop the particle system
*
* Prototype: fun [PInstance DMI S S I PlugParticle] I
*
* \param PInstance : plugIT instance
* \param DMI : DMS module who call the action (not used)
* \param S : name of the launched action
* \param S : data posted in DMS action link
* \param I : reply flag (not used)
* \param PlugParticle : particle instance structure
*
* \return I : 0
**/
fun cbStopParticle(inst, from, action, param, rep, ppartstr) =
SO3ParticleSystemSetEnable ppartstr.PPART_object 0;
0;;
/*! \brief Callback on "Set speed" dms action
*
* Change the particle system speed
*
* Prototype: fun [PInstance DMI S S I PlugParticle] I
*
* \param PInstance : plugIT instance
* \param DMI : DMS module who call the action (not used)
* \param S : name of the launched action
* \param S : data posted in DMS action link
* \param I : reply flag (not used)
* \param PlugParticle : particle instance structure
*
* \return I : 0
**/
fun cbSpeedParticle(inst, from, action, param, rep, ppartstr) =
if param == nil then nil else
(
set ppartstr.PPART_fSpeed = atof param;
SO3ParticleSystemSetSpeedFactor ppartstr.PPART_object ppartstr.PPART_fSpeed;
);
0;;
/*! \brief Callback on "Reset" dms action
*
* Reset the particle system
*
* Prototype: fun [PInstance DMI S S I PlugParticle] I
*
* \param PInstance : plugIT instance
* \param DMI : DMS module who call the action (not used)
* \param S : name of the launched action
* \param S : data posted in DMS action link
* \param I : reply flag (not used)
* \param PlugParticle : particle instance structure
*
* \return I : 0
**/
fun cbResetParticle(inst, from, action, param, rep, ppartstr) =
SO3ParticleSystemClear ppartstr.PPART_object;
0;;
/*! \brief Callback on new plugIT instance
*
* Read the parameters from editor values and initialize the instance
*
* Prototype: fun [PInstance] I
*
* \param PInstance : plugIT instance
*
* \return I : 0
**/
fun newOb(inst)=
let (getPluginInstanceParam inst "object") -> objname in
let atof (getPluginInstanceParam inst "speed") -> speed in
let atoi (getPluginInstanceParam inst "enable") -> enable in
let if enable == nil then 0 else enable -> enable in
let V3DgetObjectByName c3dXsession objname -> obj in
let mkPlugParticle [inst obj speed] -> ppartstr in
(
//reset particle system
SO3ParticleSystemSetEnable ppartstr.PPART_object 0;
SO3ParticleSystemClear ppartstr.PPART_object;
SO3ParticleSystemSetSpeedFactor ppartstr.PPART_object ppartstr.PPART_fSpeed;
SO3ParticleSystemSetEnable ppartstr.PPART_object enable;
PluginRegisterAction inst "Play" mkfun6 @cbPlayParticle ppartstr;
PluginRegisterAction inst "Pause" mkfun6 @cbPauseParticle ppartstr;
PluginRegisterAction inst "Stop" mkfun6 @cbStopParticle ppartstr;
PluginRegisterAction inst "Set speed" mkfun6 @cbSpeedParticle ppartstr;
PluginRegisterAction inst "Reset" mkfun6 @cbResetParticle ppartstr;
setPluginInstanceCbDel inst mkfun2 @deleteOb ppartstr;
);
0;;
/*! \brief Global plugIT function to initialize the plugIT callbacks
*
* Prototype: fun [S] I
*
* \param S : plugIT file path
*
* \return I : 0
**/
fun IniPlug(file)=
PlugRegister @newOb nil;
setPluginEditor @dynamicedit;
0;;