|
@@ -50,6 +50,27 @@ Entity *SceneParticleEmitter::Clone(bool deepClone, bool ignoreEditorOnly) const
|
|
|
return newEmitter;
|
|
return newEmitter;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void SceneParticleEmitter::addSourceMesh(Mesh *mesh) {
|
|
|
|
|
+ sourceMeshes.push_back(mesh);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+int SceneParticleEmitter::getNumSourceMeshes() {
|
|
|
|
|
+ return sourceMeshes.size();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+Mesh *SceneParticleEmitter::getSourcesMeshAtIndex(int index) {
|
|
|
|
|
+ if(index > 0 && index < sourceMeshes.size()) {
|
|
|
|
|
+ return sourceMeshes[index];
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void SceneParticleEmitter::removeSourceMeshAtIndex(int index) {
|
|
|
|
|
+ if(index > 0 && index < sourceMeshes.size()) {
|
|
|
|
|
+ sourceMeshes.erase(sourceMeshes.begin() + index);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void SceneParticleEmitter::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const {
|
|
void SceneParticleEmitter::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const {
|
|
|
|
|
|
|
|
SceneMesh::applyClone(clone, deepClone, ignoreEditorOnly);
|
|
SceneMesh::applyClone(clone, deepClone, ignoreEditorOnly);
|
|
@@ -87,6 +108,13 @@ void SceneParticleEmitter::applyClone(Entity *clone, bool deepClone, bool ignore
|
|
|
|
|
|
|
|
void SceneParticleEmitter::resetParticle(unsigned int index) {
|
|
void SceneParticleEmitter::resetParticle(unsigned int index) {
|
|
|
particles[index].lifetime = 0.0;
|
|
particles[index].lifetime = 0.0;
|
|
|
|
|
+
|
|
|
|
|
+ if(sourceMeshes.size() > 0) {
|
|
|
|
|
+ particles[index].varianceIndex = rand() % sourceMeshes.size();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ particles[index].varianceIndex = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
q.fromAxes(-directionDeviation.x + (directionDeviation.x * RANDOM_NUMBER * 2.0), -directionDeviation.y + (directionDeviation.y * RANDOM_NUMBER * 2.0), -directionDeviation.z + (directionDeviation.z * RANDOM_NUMBER * 2.0));
|
|
q.fromAxes(-directionDeviation.x + (directionDeviation.x * RANDOM_NUMBER * 2.0), -directionDeviation.y + (directionDeviation.y * RANDOM_NUMBER * 2.0), -directionDeviation.z + (directionDeviation.z * RANDOM_NUMBER * 2.0));
|
|
|
particles[index].velocity = q.applyTo(directionVector);
|
|
particles[index].velocity = q.applyTo(directionVector);
|
|
|
particles[index].position = Vector3(-emitterSize.x + (emitterSize.x * RANDOM_NUMBER * 2.0), -emitterSize.y + (emitterSize.y * RANDOM_NUMBER * 2.0), -emitterSize.z + (emitterSize.z * RANDOM_NUMBER * 2.0));
|
|
particles[index].position = Vector3(-emitterSize.x + (emitterSize.x * RANDOM_NUMBER * 2.0), -emitterSize.y + (emitterSize.y * RANDOM_NUMBER * 2.0), -emitterSize.z + (emitterSize.z * RANDOM_NUMBER * 2.0));
|
|
@@ -186,9 +214,9 @@ void SceneParticleEmitter::rebuildParticles() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
|
|
+ case PARTICLE_TYPE_MESH:
|
|
|
case PARTICLE_TYPE_QUAD:
|
|
case PARTICLE_TYPE_QUAD:
|
|
|
{
|
|
{
|
|
|
- mesh->setMeshType(Mesh::QUAD_MESH);
|
|
|
|
|
Matrix4 cameraMatrix = renderer->getCameraMatrix();
|
|
Matrix4 cameraMatrix = renderer->getCameraMatrix();
|
|
|
Quaternion q;
|
|
Quaternion q;
|
|
|
|
|
|
|
@@ -207,25 +235,55 @@ void SceneParticleEmitter::rebuildParticles() {
|
|
|
particlePosition = inverseMatrix * particlePosition;
|
|
particlePosition = inverseMatrix * particlePosition;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Vector3 vertexPosition = Vector3(-finalParticleSize, -finalParticleSize, 0.0);
|
|
|
|
|
- vertexPosition = q.applyTo(vertexPosition);
|
|
|
|
|
- vertexPosition = cameraMatrix.rotateVector(vertexPosition);
|
|
|
|
|
- mesh->addVertex(particlePosition.x+vertexPosition.x, particlePosition.y+vertexPosition.y, particlePosition.z+vertexPosition.z, 0.0, 0.0)->vertexColor = vertexColor;
|
|
|
|
|
-
|
|
|
|
|
- vertexPosition = Vector3(finalParticleSize, -finalParticleSize, 0.0);
|
|
|
|
|
- vertexPosition = q.applyTo(vertexPosition);
|
|
|
|
|
- vertexPosition = cameraMatrix.rotateVector(vertexPosition);
|
|
|
|
|
- mesh->addVertex(particlePosition.x+vertexPosition.x, particlePosition.y+vertexPosition.y, particlePosition.z+vertexPosition.z, 1.0, 0.0)->vertexColor = vertexColor;
|
|
|
|
|
-
|
|
|
|
|
- vertexPosition = Vector3(finalParticleSize, finalParticleSize, 0.0);
|
|
|
|
|
- vertexPosition = q.applyTo(vertexPosition);
|
|
|
|
|
- vertexPosition = cameraMatrix.rotateVector(vertexPosition);
|
|
|
|
|
- mesh->addVertex(particlePosition.x+vertexPosition.x, particlePosition.y+vertexPosition.y, particlePosition.z+vertexPosition.z, 1.0, 1.0)->vertexColor = vertexColor;
|
|
|
|
|
-
|
|
|
|
|
- vertexPosition = Vector3(-finalParticleSize, finalParticleSize, 0.0);
|
|
|
|
|
- vertexPosition = q.applyTo(vertexPosition);
|
|
|
|
|
- vertexPosition = cameraMatrix.rotateVector(vertexPosition);
|
|
|
|
|
- mesh->addVertex(particlePosition.x+vertexPosition.x, particlePosition.y+vertexPosition.y, particlePosition.z+vertexPosition.z, 0.0, 1.0)->vertexColor = vertexColor;
|
|
|
|
|
|
|
+ if(particleType == PARTICLE_TYPE_MESH) {
|
|
|
|
|
+ mesh->setMeshType(Mesh::TRI_MESH);
|
|
|
|
|
+
|
|
|
|
|
+ int indexOffset = 0;
|
|
|
|
|
+
|
|
|
|
|
+ int meshIndex = particles[i].varianceIndex;
|
|
|
|
|
+ if(meshIndex < sourceMeshes.size()) {
|
|
|
|
|
+
|
|
|
|
|
+ indexOffset = mesh->getActualVertexCount();
|
|
|
|
|
+
|
|
|
|
|
+ for(int v=0; v < sourceMeshes[meshIndex]->getActualVertexCount(); v++) {
|
|
|
|
|
+ Vertex *sv = sourceMeshes[meshIndex]->getActualVertex(v);
|
|
|
|
|
+ Vector3 vpos = Vector3(sv->x, sv->y, sv->z) * finalParticleSize;
|
|
|
|
|
+ vpos = q.applyTo(vpos);
|
|
|
|
|
+
|
|
|
|
|
+ vpos += particlePosition;
|
|
|
|
|
+ Vertex *newV = mesh->addVertex(vpos.x, vpos.y, vpos.z, sv->texCoord.x, sv->texCoord.y);
|
|
|
|
|
+ newV->vertexColor = vertexColor;
|
|
|
|
|
+ newV->normal = q.applyTo(sv->normal);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for(int v=0; v < sourceMeshes[meshIndex]->getIndexCount(); v++) {
|
|
|
|
|
+ mesh->addIndex(indexOffset + sourceMeshes[meshIndex]->getIndexAt(v));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ mesh->setMeshType(Mesh::QUAD_MESH);
|
|
|
|
|
+
|
|
|
|
|
+ Vector3 vertexPosition = Vector3(-finalParticleSize, -finalParticleSize, 0.0);
|
|
|
|
|
+ vertexPosition = q.applyTo(vertexPosition);
|
|
|
|
|
+ vertexPosition = cameraMatrix.rotateVector(vertexPosition);
|
|
|
|
|
+ mesh->addVertex(particlePosition.x+vertexPosition.x, particlePosition.y+vertexPosition.y, particlePosition.z+vertexPosition.z, 0.0, 0.0)->vertexColor = vertexColor;
|
|
|
|
|
+
|
|
|
|
|
+ vertexPosition = Vector3(finalParticleSize, -finalParticleSize, 0.0);
|
|
|
|
|
+ vertexPosition = q.applyTo(vertexPosition);
|
|
|
|
|
+ vertexPosition = cameraMatrix.rotateVector(vertexPosition);
|
|
|
|
|
+ mesh->addVertex(particlePosition.x+vertexPosition.x, particlePosition.y+vertexPosition.y, particlePosition.z+vertexPosition.z, 1.0, 0.0)->vertexColor = vertexColor;
|
|
|
|
|
+
|
|
|
|
|
+ vertexPosition = Vector3(finalParticleSize, finalParticleSize, 0.0);
|
|
|
|
|
+ vertexPosition = q.applyTo(vertexPosition);
|
|
|
|
|
+ vertexPosition = cameraMatrix.rotateVector(vertexPosition);
|
|
|
|
|
+ mesh->addVertex(particlePosition.x+vertexPosition.x, particlePosition.y+vertexPosition.y, particlePosition.z+vertexPosition.z, 1.0, 1.0)->vertexColor = vertexColor;
|
|
|
|
|
+
|
|
|
|
|
+ vertexPosition = Vector3(-finalParticleSize, finalParticleSize, 0.0);
|
|
|
|
|
+ vertexPosition = q.applyTo(vertexPosition);
|
|
|
|
|
+ vertexPosition = cameraMatrix.rotateVector(vertexPosition);
|
|
|
|
|
+ mesh->addVertex(particlePosition.x+vertexPosition.x, particlePosition.y+vertexPosition.y, particlePosition.z+vertexPosition.z, 0.0, 1.0)->vertexColor = vertexColor;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -234,8 +292,10 @@ void SceneParticleEmitter::rebuildParticles() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
mesh->dirtyArrays();
|
|
mesh->dirtyArrays();
|
|
|
-// mesh->dirtyArray(RenderDataArray::VERTEX_DATA_ARRAY);
|
|
|
|
|
- // mesh->dirtyArray(RenderDataArray::COLOR_DATA_ARRAY);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if(useVertexBuffer) {
|
|
|
|
|
+ CoreServices::getInstance()->getRenderer()->createVertexBufferForMesh(mesh);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
unsigned int SceneParticleEmitter::getParticleCount() const {
|
|
unsigned int SceneParticleEmitter::getParticleCount() const {
|