ParticleSystemParticleTrailGenerator::EventDescVector ParticleSystemParticleTrailGenerator::getConnectableEvents(void) const
{
    if(getParticleSystem() != NULL)
    {
        return getParticleSystem()->getConnectableEvents();
    }
    else
    {
        return Inherited::getConnectableEvents();
    }
}
bool
ParticleSystemParticleTrailGenerator::disconnectFromEvent(EventDescription const * eventDesc) const
{
    if(getParticleSystem() != NULL)
    {
        return getParticleSystem()->disconnectFromEvent(eventDesc);
    }
    else
    {
        return Inherited::disconnectFromEvent(eventDesc);
    }
}
Ejemplo n.º 3
0
void Emitter::emitParticles(double dt)
{
    int n = mCounter->numParticlesToCreate(dt);
    if (n == 0)
        return;

    osg::Matrix worldToPs;

    // maybe this could be optimized by halting at the lowest common ancestor of the particle and emitter nodes
    osg::NodePathList partsysNodePaths = getParticleSystem()->getParentalNodePaths();
    if (!partsysNodePaths.empty())
    {
        osg::Matrix psToWorld = osg::computeLocalToWorld(partsysNodePaths[0]);
        worldToPs = osg::Matrix::inverse(psToWorld);
    }

    const osg::Matrix& ltw = getLocalToWorldMatrix();
    osg::Matrix emitterToPs = ltw * worldToPs;

    if (!mTargets.empty())
    {
        int randomRecIndex = mTargets[(std::rand() / (static_cast<double>(RAND_MAX)+1.0)) * mTargets.size()];

        // we could use a map here for faster lookup
        FindGroupByRecIndex visitor(randomRecIndex);
        getParent(0)->accept(visitor);

        if (!visitor.mFound)
        {
            std::cerr << "Emitter: Can't find emitter node" << randomRecIndex << std::endl;
            return;
        }

        osg::NodePath path = visitor.mFoundPath;
        path.erase(path.begin());
        emitterToPs = osg::computeLocalToWorld(path) * emitterToPs;
    }

    emitterToPs.orthoNormalize(emitterToPs);

    for (int i=0; i<n; ++i)
    {
        osgParticle::Particle* P = getParticleSystem()->createParticle(0);
        if (P)
        {
            mPlacer->place(P);

            mShooter->shoot(P);

            P->transformPositionVelocity(emitterToPs);
        }
    }
}
void ParticleSystemParticleTrailGenerator::internalTrailSectGenerated(const TrailSection& ts,const Vec3f& ppVel)
{
    Color4f color;
    Real32 transp = 1.0f;
    if(getTransparencyDistribution() != NULL) transp = getTransparencyDistribution()->generate();
    if(getColorDistribution() == NULL)
    {
        color = Color4f(1.0f,1.0f,1.0f,transp);
    }
    else
    {
        Vec3f col = getColorDistribution()->generate();
        color = Color4f(col.x(),col.y(),col.z(),transp);
    }

    Vec3f vel(0.0f,0.0f,0.0f);
    switch(getVelocitySource())
    {
        case PARENT_PARTICLE:
            vel = ppVel;
            break;
        case BLEND:
            if(getVelocityDistribution() != NULL)
            {
                vel = (ppVel + getVelocityDistribution()->generate())*0.5;
            } else vel = ppVel;
            break;
        case DISTRIBUTION:
            if(getVelocityDistribution() != NULL)
            {
                vel = getVelocityDistribution()->generate();
            }
            break;
        case NONE:
        default:
            // no velocity
            break;

    }

    // add particle
    getParticleSystem()->addParticle(ts.pos, // position
                                     (getNormalDistribution() == NULL)?(Vec3f(0.0,1.0,0.0)):(getNormalDistribution()->generate()), // normal
                                     color, // color
                                     (getSizeDistribution() == NULL)?(Vec3f(1.0f,1.0f,1.0f)):(getSizeDistribution()->generate()),    // size
                                     (getTrailResolutionMethod() == TIME_SPACING)?(getTrailLength()):(-1.0f),// lifespan
                                     vel * getVelocityMultiplier(), //velocity
                                     (getAccelerationDistribution() == NULL)?(Vec3f(0.0f,0.0f,0.0f)):(getAccelerationDistribution()->generate())); // acceleration
    // ID will be of the last particle added, whose index will always be numParticles-1
    UInt32 particleID = _mTrailIDtoParticleIDMap[ts.ID];
    _mTrailIDtoParticleIDMap[ts.ID] = getParticleSystem()->getID((getParticleSystem()->getNumParticles())-1);
}    
boost::signals2::connection 
ParticleSystemParticleTrailGenerator::connectToEvent(EventDescription const * eventDesc,
                          ReflexiveContainer* const eventProducer) const
{
    if(getParticleSystem() != NULL)
    {
        return getParticleSystem()->connectToEvent(eventDesc,eventProducer);
    }
    else
    {
        return Inherited::connectToEvent(eventDesc,eventProducer);
    }
}
void ParticleSystemParticleTrailGenerator::internalTrailSectKilled(const TrailSection& ts)
{
    // remove particle
    if(getTrailResolutionMethod() != TIME_SPACING)
    {
        getParticleSystem()->killParticleByID(_mTrailIDtoParticleIDMap[ts.ID]);
    }
    _mTrailIDtoParticleIDMap.erase(ts.ID);
}
	void ParticleSystemObject::setActive(bool active)
	{
		ParticleSystem* part = getParticleSystem();
		unsigned int numEmitters = part->getNumEmitters();
		for (unsigned int emitterIdx = 0; emitterIdx < numEmitters; emitterIdx++)
		{
			part->getEmitter(emitterIdx)->setEnabled(active);
		}
	}
Ejemplo n.º 8
0
bool ParticleFactory::eraseParticleSystem(string const & fn){
  ParticleSystem * toDel = getParticleSystem(fn);
  delete toDel;

  int i = particleSystemList.erase(fn);

  if(i == 0){
    cout << "Particle system not found: " << fn << endl;
    return false;
  }

  return true;
}
Ejemplo n.º 9
0
void osgParticleHPS::ModularEmitter::emit(double dt) 
{
    int n = counter_->numParticlesToCreate(dt);
    for (int i=0; i<n; ++i) {
        Particle *P = getParticleSystem()->createParticle();
        if (P) {
            placer_->place(P);
            shooter_->shoot(P);
            if (getReferenceFrame() == RELATIVE_TO_PARENTS) {
                P->transformPositionVelocity(getLocalToWorldMatrix());
            }
        }
    }
}
Ejemplo n.º 10
0
void osgParticle::ModularProgram::execute(double dt)
{
    Operator_vector::iterator ci;
    Operator_vector::iterator ci_end = _operators.end();

    ParticleSystem* ps = getParticleSystem();
    for (ci=_operators.begin(); ci!=ci_end; ++ci) {
        (*ci)->beginOperate(this);
        int n = ps->numParticles();
        for (int i=0; i<n; ++i) {
            Particle* P = ps->getParticle(i);
            if (P->isAlive() && (*ci)->isEnabled()) {
                (*ci)->operate(P, dt);
            }
        }
        (*ci)->endOperate();
    }
}
Ejemplo n.º 11
0
void ParticleEditor::OpenConfigFile(QString filename)
{
	QFile sFile(fileName);
	if (sFile.open(QIODevice::ReadOnly | QIODevice::Text)){
		QTextStream in(&sFile);
		QString content = in.readAll();
		QJsonParseError jsonError;
		QJsonDocument document = QJsonDocument::fromJson(content.toLatin1(), &jsonError);
		if (jsonError.error == QJsonParseError::NoError && document.isObject()){
			QJsonObject obj = document.object();
			QJsonArray resList = obj["resList"].toArray();
			QJsonObject particleData = obj["particleData"].toObject();

			resourceView->clearResourceList();
			for (int i = 0; i < resList.size(); i++){
				resourceView->addRes(resList.at(i).toString());
			}

			auto layer = dynamic_cast<C3DLayer*>(g_Layer);
			auto particleSystem = layer->getParticleSystem();
			auto acclerationMin = Vec3(particleData["accleration_min_x"].toDouble(), particleData["accleration_min_y"].toDouble(), particleData["accleration_min_z"].toDouble());
			auto acclerationMax = Vec3(particleData["accleration_max_x"].toDouble(), particleData["accleration_max_y"].toDouble(), particleData["accleration_max_z"].toDouble());
			auto sizeMin = Vec3(particleData["size_min_x"].toDouble(), particleData["size_min_y"].toDouble(), particleData["size_min_z"].toDouble());
			auto sizeMax = Vec3(particleData["size_max_x"].toDouble(), particleData["size_max_y"].toDouble(), particleData["size_max_z"].toDouble());
			auto sizeVelocity = Vec3(particleData["size_velocity_x"].toDouble(), particleData["size_velocity_z"].toDouble(), particleData["size_velocity_z"].toDouble());
			auto velocityMin = Vec3(particleData["velocity_min_x"].toDouble(), particleData["velocity_min_y"].toDouble(), particleData["velocity_min_z"].toDouble());
			auto velocityMax = Vec3(particleData["velocity_max_x"].toDouble(), particleData["velocity_max_y"].toDouble(), particleData["velocity_max_z"].toDouble());
			auto colorMin = Vec3(particleData["color_min_x"].toDouble(), particleData["color_min_y"].toDouble(), particleData["color_min_z"].toDouble());
			auto colorMax = Vec3(particleData["color_max_x"].toDouble(), particleData["color_max_y"].toDouble(), particleData["color_max_z"].toDouble());
			auto colorVelocity = Vec3(particleData["color_velocity_x"].toDouble(), particleData["color_velocity_y"].toDouble(), particleData["color_velocity_z"].toDouble());
			auto life = Vec3(particleData["life_min"].toDouble(), particleData["life_max"].toDouble(), particleData["life_velocity"].toDouble());
			particleSystem->resetParticleAccelerationMin(acclerationMin);
			particleSystem->resetParticleAccelerationMax(acclerationMax);
			particleSystem->resetParticleSizeMin(sizeMin);
			particleSystem->resetParticleSizeMax(sizeMax);
			particleSystem->resetParticleSizeVelocity(sizeVelocity);
			particleSystem->resetParticleVelocityMin(velocityMin); 
			particleSystem->resetParticleVelocityMax(velocityMax);
			particleSystem->resetParticleColorMin(colorMin);
			particleSystem->resetParticleColorMax(colorMax);
			particleSystem->resetParticleColorVelocity(colorVelocity);
			particleSystem->resetParticleLifeMin(life.x);
			particleSystem->resetParticleLifeMax(life.y); 
			particleSystem->resetParticleLife_Velocity(life.z);
			particleSystem->SetTexture(particleData["texture"].toString().toLocal8Bit().data());
			particleSystem->setColor(particleData["m_color_r"].toDouble(), particleData["m_color_g"].toDouble(), particleData["m_color_b"].toDouble(), particleData["m_color_a"].toDouble());
			eParticleType _type;
			switch (particleData["particle_type"].toInt()){
			case 0:
				_type = eParticleType::PT_FIRE;
				break;
			case 1:
				_type = eParticleType::PT_FIREWORK;
				break;
			case 2:
				_type = eParticleType::PT_FOUNTAIN;
				break;
			case 3:
				_type = eParticleType::PT_MAX;
				break;
			}
			layer->resetParticle(particleData["count"].toInt(), _type, { particleData["blendfunc_src"].toInt(), particleData["blendfunc_dst"].toInt() });
			controlView->setTarget(particleSystem);
			controlView->setParticleType(_type);
		}
		else{
			addConsoleInfo("文件错误");
		}
	}
	else{
		addConsoleInfo("读取文件错误");
	}
}
Ejemplo n.º 12
0
void ParticleEditor::SaveConfigFile(QString filename)
{
	FILE* sFile;
	sFile = fopen(filename.toLocal8Bit().data(), "wb");
	if (!sFile){
		addConsoleInfo("保存失败");
		return;
	}
	QVariantMap document;
	QVariantList resList;
	QVariantMap particleData;

	//导出资源
	QStringList imageList = resourceView->getImageList();
	for (int i = 0; i < imageList.size(); i++){
		QVariant res = imageList.at(i);
		resList.append(res);
	}

	//导出粒子
	auto layer = dynamic_cast<C3DLayer*>(g_Layer);
	auto particleSystem = layer->getParticleSystem();
	particleData.insert("texture", particleSystem->getTextureFileName().c_str());
	particleData.insert("count", particleSystem->getParticleCount());
	particleData.insert("particle_type", particleSystem->getParticleType());
	particleData.insert("blendfunc_src", particleSystem->getBlendFunc().src);
	particleData.insert("blendfunc_dst", particleSystem->getBlendFunc().dst);
	auto data = particleSystem->getParticleData();
	particleData.insert("velocity_min_x", data.m_Velocity_Min.x);
	particleData.insert("velocity_min_y", data.m_Velocity_Min.y);
	particleData.insert("velocity_min_z", data.m_Velocity_Min.z);
	particleData.insert("velocity_max_x", data.m_Velocity_Max.x);
	particleData.insert("velocity_max_y", data.m_Velocity_Max.y);
	particleData.insert("velocity_max_z", data.m_Velocity_Max.z);
	particleData.insert("accleration_min_x", data.m_Acceleration_Min.x);
	particleData.insert("accleration_min_y", data.m_Acceleration_Min.y);
	particleData.insert("accleration_min_z", data.m_Acceleration_Min.z);
	particleData.insert("accleration_max_x", data.m_Acceleration_Max.x);
	particleData.insert("accleration_max_y", data.m_Acceleration_Max.y);
	particleData.insert("accleration_max_z", data.m_Acceleration_Max.z);
	particleData.insert("size_min_x", data.m_Size_Min.x);
	particleData.insert("size_min_y", data.m_Size_Min.y);
	particleData.insert("size_min_z", data.m_Size_Min.z);
	particleData.insert("size_max_x", data.m_Size_Max.x);
	particleData.insert("size_max_y", data.m_Size_Max.y);
	particleData.insert("size_max_z", data.m_Size_Max.z);
	particleData.insert("size_velocity_x", data.m_Size_Velocity.x);
	particleData.insert("size_velocity_y", data.m_Size_Velocity.y);
	particleData.insert("size_velocity_z", data.m_Size_Velocity.z);
	particleData.insert("color_min_x", data.m_Color_Min.x);
	particleData.insert("color_min_y", data.m_Color_Min.y);
	particleData.insert("color_min_z", data.m_Color_Min.z);
	particleData.insert("color_max_x", data.m_Color_Max.x);
	particleData.insert("color_max_y", data.m_Color_Max.y);
	particleData.insert("color_max_z", data.m_Color_Max.z);
	particleData.insert("color_velocity_x", data.m_Color_Velocity.x);
	particleData.insert("color_velocity_y", data.m_Color_Velocity.y);
	particleData.insert("color_velocity_z", data.m_Color_Velocity.z);
	particleData.insert("life_min", data.m_Life_Min);
	particleData.insert("life_max", data.m_Life_Max);
	particleData.insert("life_velocity", data.m_Life_Velocity);
	particleData.insert("m_color_r", particleSystem->getColor()[0]);
	particleData.insert("m_color_g", particleSystem->getColor()[1]);
	particleData.insert("m_color_b", particleSystem->getColor()[2]);
	particleData.insert("m_color_a", particleSystem->getColor()[3]);
	document.insert("resList", resList);
	document.insert("particleData", particleData);
	QJsonDocument jsonDocument = QJsonDocument::fromVariant(document);
	QByteArray array = jsonDocument.toJson(QJsonDocument::Compact);
	unsigned int count = array.size();
	const char* data__ = (const char*)array.data();
	fwrite(data__, count, 1, sFile);
	fclose(sFile);
}