How can we achieve Earthquake Simulation in Unity - Simulation of P and S Waves
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}
up vote
1
down vote
favorite
I Cannot use Water waves as P and S Waves are different than water waves. I tried to use it but not satisfied with the result.
I am trying to simulate how Earthquake takes place in real time which you cannot simulate in the real world. Here is the reference link to understand the basics of Earthquake and to understand better here is the better-simulated Example. I wanted to Simulate P and S Waves. My first attempt will be simulating with mesh instead of showing lines, I don't know how to compress mesh (P Waves) but I found out a good example to simulate wave like effect (S Waves).
The solution I am looking forward to is :
- Any idea of how I can compress - decompress mesh in Unity (P Waves).
- wave like effect (S waves), I have an example but it moves only Plane, in my case, i want to do more like a deformation of mesh, so it gives me an real effect like S Waves.
mesh dynamic-mesh
add a comment |
up vote
1
down vote
favorite
I Cannot use Water waves as P and S Waves are different than water waves. I tried to use it but not satisfied with the result.
I am trying to simulate how Earthquake takes place in real time which you cannot simulate in the real world. Here is the reference link to understand the basics of Earthquake and to understand better here is the better-simulated Example. I wanted to Simulate P and S Waves. My first attempt will be simulating with mesh instead of showing lines, I don't know how to compress mesh (P Waves) but I found out a good example to simulate wave like effect (S Waves).
The solution I am looking forward to is :
- Any idea of how I can compress - decompress mesh in Unity (P Waves).
- wave like effect (S waves), I have an example but it moves only Plane, in my case, i want to do more like a deformation of mesh, so it gives me an real effect like S Waves.
mesh dynamic-mesh
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I Cannot use Water waves as P and S Waves are different than water waves. I tried to use it but not satisfied with the result.
I am trying to simulate how Earthquake takes place in real time which you cannot simulate in the real world. Here is the reference link to understand the basics of Earthquake and to understand better here is the better-simulated Example. I wanted to Simulate P and S Waves. My first attempt will be simulating with mesh instead of showing lines, I don't know how to compress mesh (P Waves) but I found out a good example to simulate wave like effect (S Waves).
The solution I am looking forward to is :
- Any idea of how I can compress - decompress mesh in Unity (P Waves).
- wave like effect (S waves), I have an example but it moves only Plane, in my case, i want to do more like a deformation of mesh, so it gives me an real effect like S Waves.
mesh dynamic-mesh
I Cannot use Water waves as P and S Waves are different than water waves. I tried to use it but not satisfied with the result.
I am trying to simulate how Earthquake takes place in real time which you cannot simulate in the real world. Here is the reference link to understand the basics of Earthquake and to understand better here is the better-simulated Example. I wanted to Simulate P and S Waves. My first attempt will be simulating with mesh instead of showing lines, I don't know how to compress mesh (P Waves) but I found out a good example to simulate wave like effect (S Waves).
The solution I am looking forward to is :
- Any idea of how I can compress - decompress mesh in Unity (P Waves).
- wave like effect (S waves), I have an example but it moves only Plane, in my case, i want to do more like a deformation of mesh, so it gives me an real effect like S Waves.
mesh dynamic-mesh
mesh dynamic-mesh
asked Dec 3 at 8:28
Kartik Shah
469
469
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
In order to do this you will have to write some code to modify the mesh programmatically. This is how you read the vertices of a mesh from a C# script:
Mesh mesh = GetComponent<MeshFilter>().mesh;
Vector3 vertices = mesh.vertices;
And this is how you write them back:
mesh.vertices = vertices;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
mesh.RecalculateTangents();
(Note that depending on the shader your mesh is using, recalculating the normals and/or tangents might not actually be needed. If you comment it out and the light on the mesh still looks correct, you can leave it out).
Now about the complicated part: Calculating the deformation of your mesh. I think the best way to do this would be to create a copy of the original vertex array in the Start method. Your Update method should now take that original array and run each vertex through a function which takes the vertex and a timecode as input and then returns a new vertex which says where that vertex should be at that timecode.
I am not a seismologist, so I can't tell you how this function would look exactly for physically correct S-waves or P-waves. So here is an example which applies a simple sine wave to the z-axis of the mesh which travels in x direction. You should be able to edit the wave functions to do what you want it to do:
private Vector3 originalVertices;
private Mesh mesh;
void Start() {
mesh = GetComponent<MeshFilter>().mesh;
originalVertices = mesh.vertices;
}
void Update() {
Vector3 newVertices = new Vector3[originalVertices.Length];
for(int i = 0; i < originalVertices.Length; i++) {
newVertices[i] = WaveFunction(originalVertices[i], Time.time);
}
mesh.vertices = newVertices;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
mesh.RecalculateTangents();
}
private Vector3 WaveFunction(Vector3 origin, float timeCode) {
// sine wave with an amplitude of 1 unit and a period of 2π units,
// traveling with a speed of 1 unit per second.
// Change this to your own wave function.
return new Vector3 (
origin.x,
origin.y,
origin.z + Mathf.Sin(in.x + timeCode)
);
}
My testing mesh in Blender:
The result in Unity (quite hypnotic):
your code really helps me and takes me one step further to the result I wanted. I need one further help from you. check out P wave and Rayleigh wave in the link. I wanted to do the same in Mesh, but I have no idea how to make the upper part of mesh in moving and lower part of the same mesh still.
– Kartik Shah
2 days ago
@KartikShah As I wrote: We are game developers, not a seismologists. If you want to know more about the math which can be used to describe different kinds of seismic waves, you should ask on Earth Science Stack Exchange
– Philipp
2 days ago
I want your help in mesh editing, that link have the GIF of how mesh movement is done in the wave although thanks for the help.
– Kartik Shah
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
In order to do this you will have to write some code to modify the mesh programmatically. This is how you read the vertices of a mesh from a C# script:
Mesh mesh = GetComponent<MeshFilter>().mesh;
Vector3 vertices = mesh.vertices;
And this is how you write them back:
mesh.vertices = vertices;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
mesh.RecalculateTangents();
(Note that depending on the shader your mesh is using, recalculating the normals and/or tangents might not actually be needed. If you comment it out and the light on the mesh still looks correct, you can leave it out).
Now about the complicated part: Calculating the deformation of your mesh. I think the best way to do this would be to create a copy of the original vertex array in the Start method. Your Update method should now take that original array and run each vertex through a function which takes the vertex and a timecode as input and then returns a new vertex which says where that vertex should be at that timecode.
I am not a seismologist, so I can't tell you how this function would look exactly for physically correct S-waves or P-waves. So here is an example which applies a simple sine wave to the z-axis of the mesh which travels in x direction. You should be able to edit the wave functions to do what you want it to do:
private Vector3 originalVertices;
private Mesh mesh;
void Start() {
mesh = GetComponent<MeshFilter>().mesh;
originalVertices = mesh.vertices;
}
void Update() {
Vector3 newVertices = new Vector3[originalVertices.Length];
for(int i = 0; i < originalVertices.Length; i++) {
newVertices[i] = WaveFunction(originalVertices[i], Time.time);
}
mesh.vertices = newVertices;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
mesh.RecalculateTangents();
}
private Vector3 WaveFunction(Vector3 origin, float timeCode) {
// sine wave with an amplitude of 1 unit and a period of 2π units,
// traveling with a speed of 1 unit per second.
// Change this to your own wave function.
return new Vector3 (
origin.x,
origin.y,
origin.z + Mathf.Sin(in.x + timeCode)
);
}
My testing mesh in Blender:
The result in Unity (quite hypnotic):
your code really helps me and takes me one step further to the result I wanted. I need one further help from you. check out P wave and Rayleigh wave in the link. I wanted to do the same in Mesh, but I have no idea how to make the upper part of mesh in moving and lower part of the same mesh still.
– Kartik Shah
2 days ago
@KartikShah As I wrote: We are game developers, not a seismologists. If you want to know more about the math which can be used to describe different kinds of seismic waves, you should ask on Earth Science Stack Exchange
– Philipp
2 days ago
I want your help in mesh editing, that link have the GIF of how mesh movement is done in the wave although thanks for the help.
– Kartik Shah
2 days ago
add a comment |
up vote
3
down vote
accepted
In order to do this you will have to write some code to modify the mesh programmatically. This is how you read the vertices of a mesh from a C# script:
Mesh mesh = GetComponent<MeshFilter>().mesh;
Vector3 vertices = mesh.vertices;
And this is how you write them back:
mesh.vertices = vertices;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
mesh.RecalculateTangents();
(Note that depending on the shader your mesh is using, recalculating the normals and/or tangents might not actually be needed. If you comment it out and the light on the mesh still looks correct, you can leave it out).
Now about the complicated part: Calculating the deformation of your mesh. I think the best way to do this would be to create a copy of the original vertex array in the Start method. Your Update method should now take that original array and run each vertex through a function which takes the vertex and a timecode as input and then returns a new vertex which says where that vertex should be at that timecode.
I am not a seismologist, so I can't tell you how this function would look exactly for physically correct S-waves or P-waves. So here is an example which applies a simple sine wave to the z-axis of the mesh which travels in x direction. You should be able to edit the wave functions to do what you want it to do:
private Vector3 originalVertices;
private Mesh mesh;
void Start() {
mesh = GetComponent<MeshFilter>().mesh;
originalVertices = mesh.vertices;
}
void Update() {
Vector3 newVertices = new Vector3[originalVertices.Length];
for(int i = 0; i < originalVertices.Length; i++) {
newVertices[i] = WaveFunction(originalVertices[i], Time.time);
}
mesh.vertices = newVertices;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
mesh.RecalculateTangents();
}
private Vector3 WaveFunction(Vector3 origin, float timeCode) {
// sine wave with an amplitude of 1 unit and a period of 2π units,
// traveling with a speed of 1 unit per second.
// Change this to your own wave function.
return new Vector3 (
origin.x,
origin.y,
origin.z + Mathf.Sin(in.x + timeCode)
);
}
My testing mesh in Blender:
The result in Unity (quite hypnotic):
your code really helps me and takes me one step further to the result I wanted. I need one further help from you. check out P wave and Rayleigh wave in the link. I wanted to do the same in Mesh, but I have no idea how to make the upper part of mesh in moving and lower part of the same mesh still.
– Kartik Shah
2 days ago
@KartikShah As I wrote: We are game developers, not a seismologists. If you want to know more about the math which can be used to describe different kinds of seismic waves, you should ask on Earth Science Stack Exchange
– Philipp
2 days ago
I want your help in mesh editing, that link have the GIF of how mesh movement is done in the wave although thanks for the help.
– Kartik Shah
2 days ago
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
In order to do this you will have to write some code to modify the mesh programmatically. This is how you read the vertices of a mesh from a C# script:
Mesh mesh = GetComponent<MeshFilter>().mesh;
Vector3 vertices = mesh.vertices;
And this is how you write them back:
mesh.vertices = vertices;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
mesh.RecalculateTangents();
(Note that depending on the shader your mesh is using, recalculating the normals and/or tangents might not actually be needed. If you comment it out and the light on the mesh still looks correct, you can leave it out).
Now about the complicated part: Calculating the deformation of your mesh. I think the best way to do this would be to create a copy of the original vertex array in the Start method. Your Update method should now take that original array and run each vertex through a function which takes the vertex and a timecode as input and then returns a new vertex which says where that vertex should be at that timecode.
I am not a seismologist, so I can't tell you how this function would look exactly for physically correct S-waves or P-waves. So here is an example which applies a simple sine wave to the z-axis of the mesh which travels in x direction. You should be able to edit the wave functions to do what you want it to do:
private Vector3 originalVertices;
private Mesh mesh;
void Start() {
mesh = GetComponent<MeshFilter>().mesh;
originalVertices = mesh.vertices;
}
void Update() {
Vector3 newVertices = new Vector3[originalVertices.Length];
for(int i = 0; i < originalVertices.Length; i++) {
newVertices[i] = WaveFunction(originalVertices[i], Time.time);
}
mesh.vertices = newVertices;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
mesh.RecalculateTangents();
}
private Vector3 WaveFunction(Vector3 origin, float timeCode) {
// sine wave with an amplitude of 1 unit and a period of 2π units,
// traveling with a speed of 1 unit per second.
// Change this to your own wave function.
return new Vector3 (
origin.x,
origin.y,
origin.z + Mathf.Sin(in.x + timeCode)
);
}
My testing mesh in Blender:
The result in Unity (quite hypnotic):
In order to do this you will have to write some code to modify the mesh programmatically. This is how you read the vertices of a mesh from a C# script:
Mesh mesh = GetComponent<MeshFilter>().mesh;
Vector3 vertices = mesh.vertices;
And this is how you write them back:
mesh.vertices = vertices;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
mesh.RecalculateTangents();
(Note that depending on the shader your mesh is using, recalculating the normals and/or tangents might not actually be needed. If you comment it out and the light on the mesh still looks correct, you can leave it out).
Now about the complicated part: Calculating the deformation of your mesh. I think the best way to do this would be to create a copy of the original vertex array in the Start method. Your Update method should now take that original array and run each vertex through a function which takes the vertex and a timecode as input and then returns a new vertex which says where that vertex should be at that timecode.
I am not a seismologist, so I can't tell you how this function would look exactly for physically correct S-waves or P-waves. So here is an example which applies a simple sine wave to the z-axis of the mesh which travels in x direction. You should be able to edit the wave functions to do what you want it to do:
private Vector3 originalVertices;
private Mesh mesh;
void Start() {
mesh = GetComponent<MeshFilter>().mesh;
originalVertices = mesh.vertices;
}
void Update() {
Vector3 newVertices = new Vector3[originalVertices.Length];
for(int i = 0; i < originalVertices.Length; i++) {
newVertices[i] = WaveFunction(originalVertices[i], Time.time);
}
mesh.vertices = newVertices;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
mesh.RecalculateTangents();
}
private Vector3 WaveFunction(Vector3 origin, float timeCode) {
// sine wave with an amplitude of 1 unit and a period of 2π units,
// traveling with a speed of 1 unit per second.
// Change this to your own wave function.
return new Vector3 (
origin.x,
origin.y,
origin.z + Mathf.Sin(in.x + timeCode)
);
}
My testing mesh in Blender:
The result in Unity (quite hypnotic):
edited Dec 3 at 20:04
answered Dec 3 at 9:56
Philipp
76.7k19180230
76.7k19180230
your code really helps me and takes me one step further to the result I wanted. I need one further help from you. check out P wave and Rayleigh wave in the link. I wanted to do the same in Mesh, but I have no idea how to make the upper part of mesh in moving and lower part of the same mesh still.
– Kartik Shah
2 days ago
@KartikShah As I wrote: We are game developers, not a seismologists. If you want to know more about the math which can be used to describe different kinds of seismic waves, you should ask on Earth Science Stack Exchange
– Philipp
2 days ago
I want your help in mesh editing, that link have the GIF of how mesh movement is done in the wave although thanks for the help.
– Kartik Shah
2 days ago
add a comment |
your code really helps me and takes me one step further to the result I wanted. I need one further help from you. check out P wave and Rayleigh wave in the link. I wanted to do the same in Mesh, but I have no idea how to make the upper part of mesh in moving and lower part of the same mesh still.
– Kartik Shah
2 days ago
@KartikShah As I wrote: We are game developers, not a seismologists. If you want to know more about the math which can be used to describe different kinds of seismic waves, you should ask on Earth Science Stack Exchange
– Philipp
2 days ago
I want your help in mesh editing, that link have the GIF of how mesh movement is done in the wave although thanks for the help.
– Kartik Shah
2 days ago
your code really helps me and takes me one step further to the result I wanted. I need one further help from you. check out P wave and Rayleigh wave in the link. I wanted to do the same in Mesh, but I have no idea how to make the upper part of mesh in moving and lower part of the same mesh still.
– Kartik Shah
2 days ago
your code really helps me and takes me one step further to the result I wanted. I need one further help from you. check out P wave and Rayleigh wave in the link. I wanted to do the same in Mesh, but I have no idea how to make the upper part of mesh in moving and lower part of the same mesh still.
– Kartik Shah
2 days ago
@KartikShah As I wrote: We are game developers, not a seismologists. If you want to know more about the math which can be used to describe different kinds of seismic waves, you should ask on Earth Science Stack Exchange
– Philipp
2 days ago
@KartikShah As I wrote: We are game developers, not a seismologists. If you want to know more about the math which can be used to describe different kinds of seismic waves, you should ask on Earth Science Stack Exchange
– Philipp
2 days ago
I want your help in mesh editing, that link have the GIF of how mesh movement is done in the wave although thanks for the help.
– Kartik Shah
2 days ago
I want your help in mesh editing, that link have the GIF of how mesh movement is done in the wave although thanks for the help.
– Kartik Shah
2 days ago
add a comment |
Thanks for contributing an answer to Game Development Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgamedev.stackexchange.com%2fquestions%2f165846%2fhow-can-we-achieve-earthquake-simulation-in-unity-simulation-of-p-and-s-waves%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown