Posts: 1
Threads: 1
Joined: Mar 2018
Reputation:
0
16-03-2018, 02:16 PM
(This post was last modified: 16-03-2018, 02:40 PM by shtolyan.)
Hello! Thank you for the wonderful asset
Can you help me with the problem of creating an emitter in the code? The object is created on the scene, all obi objects are configured, but the render does not work.
Here is my code:
public void Init()
{
GameObject emitterObject = new GameObject("emitter",
typeof(ObiEmitter),
typeof(ObiParticleRenderer));
emitterObject.transform.position = gameObject.transform.position;
emitterObject.transform.parent = gameObject.transform;
_emitter = emitterObject.GetComponent<ObiEmitter>();
_emitter.Solver = GameControllerObjects.Instance.ObiSolver;
_emitter.NumParticles = 1000;
_emitter.emissionMethod = ObiEmitter.EmissionMethod.STREAM;
_emitter.speed = ((Liquid)VRAObject.Type).Speed;
_emitter.lifespan = ((Liquid)VRAObject.Type).Lifespan;
_emitter.randomVelocity = ((Liquid)VRAObject.Type).RandomVeloncity;
_emitter.EmitterMaterial = GameControllerObjects.Instance.ObiEmitterMaterial;
Color newCol = new Color();
string htmlValue = "#" + ((Liquid)VRAObject.Type).ParticleColor;
ObiParticleRenderer particleRenderer = emitterObject.GetComponent<ObiParticleRenderer>();
if (ColorUtility.TryParseHtmlString(htmlValue, out newCol))
particleRenderer.particleColor = newCol;
particleRenderer.radiusScale = ((Liquid) VRAObject.Type).RadiusScale;
GameControllerObjects.Instance.ObiFluidRenderer.particleRenderers.Add(particleRenderer);
StartCoroutine(OnFinish());
}
IEnumerator OnFinish()
{
yield return _emitter.StartCoroutine(_emitter.GeneratePhysicRepresentationForMesh());
_emitter.AddToSolver(null);
}
Also I have Exeption!
NullReferenceException: Object reference not set to an instance of an object
Obi.ObiActor.PushDataToSolver (ParticleData data) (at Assets/Obi/Scripts/Actors/ObiActor.cs:369)
Obi.ObiActor.AddToSolver (System.Object info) (at Assets/Obi/Scripts/Actors/ObiActor.cs:276)
Obi.ObiEmitter.AddToSolver (System.Object info) (at Assets/Obi/Scripts/Actors/ObiEmitter.cs:137)
Obi.ObiActor.Start () (at Assets/Obi/Scripts/Actors/ObiActor.cs:148)
Thank you!
Posts: 19
Threads: 3
Joined: Mar 2018
Reputation:
1
Might help if you use a prefab with the emitter and then just make sure that the emitter is added to the renderer on the camera with the code?
Posts: 19
Threads: 3
Joined: Mar 2018
Reputation:
1
I am trying to make a water gun in Unity for VR. I have managed to make a gun that has an emitter on its barrel. But I have some trouble controlling when it is supposed to be emitting, and when it is supposed to stop. I also tried using two solvers, but I am guessing that is best not to do, it seems extremely demanding for the CPU.
So now I am just using one solver for both my emitters. But I seem to have several problems, the first one being able to control when to emit as I mentioned, but also it does not seem easy to control how this fluid should look. I can change its color, but it always seems to be simple colors without any shaders or they just end up invisible. The faucet water is nice and transparent and such, looking a lot more like fluid, but even though I copied everything it still ends up seeming like its lacking a shader. Am I missing something? I tried different types of fluid. Simple fluid, low res... etc. Not sure if any of those are connected with a shader. I am guessing it has more to do with how the physics of the water behaves or something like that.
I have tried controlling it by setting the emitters speed to 0 if there is a certain amount of particles on the solver or on the emitter, but that also seems to cause problems.
Posts: 6,326
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
28-03-2018, 12:14 PM
(This post was last modified: 28-03-2018, 12:17 PM by josemendez.)
(28-03-2018, 07:04 AM)Caldor Wrote: I am trying to make a water gun in Unity for VR. I have managed to make a gun that has an emitter on its barrel. But I have some trouble controlling when it is supposed to be emitting, and when it is supposed to stop. I also tried using two solvers, but I am guessing that is best not to do, it seems extremely demanding for the CPU.
So now I am just using one solver for both my emitters. But I seem to have several problems, the first one being able to control when to emit as I mentioned, but also it does not seem easy to control how this fluid should look. I can change its color, but it always seems to be simple colors without any shaders or they just end up invisible. The faucet water is nice and transparent and such, looking a lot more like fluid, but even though I copied everything it still ends up seeming like its lacking a shader. Am I missing something? I tried different types of fluid. Simple fluid, low res... etc. Not sure if any of those are connected with a shader. I am guessing it has more to do with how the physics of the water behaves or something like that.
I have tried controlling it by setting the emitters speed to 0 if there is a certain amount of particles on the solver or on the emitter, but that also seems to cause problems.
Hi there,
I think you're confusing the emitter material ( http://obi.virtualmethodstudio.com/tutor...rials.html) with the fluid rendering material ( http://obi.virtualmethodstudio.com/tutor...ering.html). The first one dictates physical properties of the fluid, the second one influcences how it looks. None of the parameters in the emitter material influence rendering in any way, they only influence the physics.
ObiFluidRenderer will use the materias you specify in its inspector. There's two materials involved in rendering fluid: the color blending material, and the fluid material.
Make sure you are using a material with the dielectric fluid shader as the "Fluid material", and the fluid colors blend shader for the "Color material", just like in the viscosity, mill, and faucet examples.
Then, you can control fluid smoothness, cloudiness, refraction, thickness, etc in the material itself.
Regarding emission: set the emitter's speed to 0 to stop emitting, set it back to any value you wish to resume emitting. As in any real-world faucet, the emission speed and the volume emitted per second are linked to ensure a continuous stream, with minimum fluctuations in pressure.
Posts: 19
Threads: 3
Joined: Mar 2018
Reputation:
1
But that is the thing, so far I am trying to control it by setting the speed to zero. I set it to zero in an update though. I think I will try to add a counter, that just ensures that it keeps having its speed for 1 second.
Regarding the materials, I copied the whole emitter component with all its values, so I might have confused the two materials, but only in my post, not in Unity. So that does not explain why the faucet fluid has one shader / material and the pistol fluid has another... or lacks one. Unless it is set somewhere else than on the emitter?
Those links sure do explain a lot, so thanks : hope I can find a solution using them.
Posts: 19
Threads: 3
Joined: Mar 2018
Reputation:
1
30-03-2018, 09:26 PM
(This post was last modified: 30-03-2018, 09:59 PM by Caldor.)
I have been playing around with it. Several things seem strange.
I set the speed of the emitter to zero at the beginning. Both emitters use the same renderer on the camera and they use the same solver... seems like that is how it is supposed to be. I tried using two solvers but that got really heavy for my system right from when I pressed play.
So they ought to be using the same materials?
Each emitter has a Obi Particle Renderer, a Obi Emitter and a Obi Emitter Shape. They both use the LowResolution emitter material and the same solver.
One emitter is on the end of the gun, so that the gun fires the particles... I did get that to work at one point, but all the particles only had one color and seemingly no material. Right now they are just invisible. When I shoot the gun, no matter where I shoot, it seems they hit the water in the bucket that came from the faucet. They also end up hitting the items I am aiming at though and pushes them around.
I have set the shooting timer to 0.3 seconds, yet it seems to be able to create more than 60 particles, and I set the speed for the emitter to 6. I started out setting the timer to 1 second and the particle limit on the emitter to 75 and it shot off all 75 within that one second with the speed set to 6.
I suspect the gun and using its emitter affects the faucet emitter as well somehow. Any ideas on how to fix this?
Edit: Seems it now even fired all 150 within the 0.3 seconds. I cannot see them so I have to rely on the emitters active particle count. Maybe the iterations set on the solver affects this? I also experimented with the faucet, and I can see that every time I activate the gun emitter, some of the particles also end up coming out of the faucet again. All the new particles are invisible though, and they do not count on the faucet emitter, only on the guns emitter.
I enabled the "render" option on the emitter, so now I can see the particles as spheres... which added a bit more strangeness. When I shoot the gun, it shoots particles. They are green... the faucet also emits particles, they are light blue. If I set the faucet emitter to render, its water particles become white. So 3 different colors... and I am not sure where they are coming from. The particle color on the faucet is its default, which is light blue, near white. The particle color on the gun emitter is a darker blue. So not sure where the green comes from... the gun is green though, so maybe it comes from the texture on the gun which is the parent of the emitter?
Posts: 19
Threads: 3
Joined: Mar 2018
Reputation:
1
I have experienced even more... the colors might make sense now. The color on the Obi Emitter Shape Disk seems to mix with the particle color. The Faucet has a color of white on the emitter, so it was just the clear version I could see, and I guess the two colors at the time on the guns emitter mixed up to be green.
Still have no clue why both emitters are activated when I change the speed of the guns emitter though. The faucet emitter keeps stating it has 1000 particles, the ones with a life span of 1000, and the other emitter seems to be accounting for both the faucet and its own particles.
I will probably experiment some more tomorrow... the missing shader is what is most annoying. They both use the same solver and the same renderer on the camera... they are supposed to use the fluid color blend for color and clear fluid for fluid as the fluid materials.
Maybe those are what I need to play around with tomorrow to see what that might change.
Posts: 19
Threads: 3
Joined: Mar 2018
Reputation:
1
31-03-2018, 09:20 AM
(This post was last modified: 31-03-2018, 09:29 AM by Caldor.)
(16-03-2018, 02:16 PM)shtolyan Wrote: Hello! Thank you for the wonderful asset
Can you help me with the problem of creating an emitter in the code? The object is created on the scene, all obi objects are configured, but the render does not work.
*removed code part*
Thank you!
I think I found your problem, because my problem was pretty much the same. When you start the Unity project and the emitter with the particle renderer is disabled, the camera with the fluid renderer does not seem to be able to find it when it is enabled again.
I guess I will have to look into the code a bit to figure out what might cause this. I am guessing taking a part of its awake script and make it something it checks now and then could help fix this, making it possible to instantiate emitters at runtime.
(28-03-2018, 12:14 PM)josemendez Wrote: Hi there,
I think you're confusing the emitter material (http://obi.virtualmethodstudio.com/tutor...rials.html) with the fluid rendering material (http://obi.virtualmethodstudio.com/tutor...ering.html). The first one dictates physical properties of the fluid, the second one influcences how it looks. None of the parameters in the emitter material influence rendering in any way, they only influence the physics.
ObiFluidRenderer will use the materias you specify in its inspector. There's two materials involved in rendering fluid: the color blending material, and the fluid material.
Make sure you are using a material with the dielectric fluid shader as the "Fluid material", and the fluid colors blend shader for the "Color material", just like in the viscosity, mill, and faucet examples.
Then, you can control fluid smoothness, cloudiness, refraction, thickness, etc in the material itself.
Regarding emission: set the emitter's speed to 0 to stop emitting, set it back to any value you wish to resume emitting. As in any real-world faucet, the emission speed and the volume emitted per second are linked to ensure a continuous stream, with minimum fluctuations in pressure.
I found my problem. My emitter was inactive / deactivated when the Unity project started and got enabled as I fired the gun. Which I guess the fluid renderer does not like. I still have one mystery though... whenever I activate the gun, by changing its emitter from 0 to 3 now, it still causes the faucet emitter to also emit particles. Any idea what might cause that?
I have made the emitter transform and its Obi Emitter script public so that I can ensure that the gun targets the two directly. I used a gameobject.find before, but even then it only found one, the one it was supposed to. Now I dont use that, and it still emits from both the faucet and the gun.
Also it would be nice to know if there is a way to use two different fluid materials at the same time? Right now the camera seems to decide which material the fluid has, rather than the emitters and the particle renderes on them.
Posts: 6,326
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
(31-03-2018, 09:20 AM)Caldor Wrote: I think I found your problem, because my problem was pretty much the same. When you start the Unity project and the emitter with the particle renderer is disabled, the camera with the fluid renderer does not seem to be able to find it when it is enabled again.
I guess I will have to look into the code a bit to figure out what might cause this. I am guessing taking a part of its awake script and make it something it checks now and then could help fix this, making it possible to instantiate emitters at runtime.
I found my problem. My emitter was inactive / deactivated when the Unity project started and got enabled as I fired the gun. Which I guess the fluid renderer does not like. I still have one mystery though... whenever I activate the gun, by changing its emitter from 0 to 3 now, it still causes the faucet emitter to also emit particles. Any idea what might cause that?
I have made the emitter transform and its Obi Emitter script public so that I can ensure that the gun targets the two directly. I used a gameobject.find before, but even then it only found one, the one it was supposed to. Now I dont use that, and it still emits from both the faucet and the gun.
Also it would be nice to know if there is a way to use two different fluid materials at the same time? Right now the camera seems to decide which material the fluid has, rather than the emitters and the particle renderes on them.
Hi there.
If you're using <3.4, you need to call fluidRenderer.SetupFluidRenderingCommandBuffer() after adding new particle renderers to the fluid renderer. In 3.4 this is not necessary (when having AutoUpdate enabled in the fluid renderer).
Regarding the faucet and the gun emitting at the same time, make sure the emitter shapes reference the appropriate emitters. You might have both shapes referencing the same emitter.
To use two )or more) different fluid materials at the same time, add two FluidRenderers to the same camera, each one referencing the appropriate particle renderer. Then give each one its own fluid material.
cheers,
Posts: 6,326
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
(31-03-2018, 09:20 AM)Caldor Wrote: I think I found your problem, because my problem was pretty much the same. When you start the Unity project and the emitter with the particle renderer is disabled, the camera with the fluid renderer does not seem to be able to find it when it is enabled again.
I guess I will have to look into the code a bit to figure out what might cause this. I am guessing taking a part of its awake script and make it something it checks now and then could help fix this, making it possible to instantiate emitters at runtime.
I found my problem. My emitter was inactive / deactivated when the Unity project started and got enabled as I fired the gun. Which I guess the fluid renderer does not like. I still have one mystery though... whenever I activate the gun, by changing its emitter from 0 to 3 now, it still causes the faucet emitter to also emit particles. Any idea what might cause that?
I have made the emitter transform and its Obi Emitter script public so that I can ensure that the gun targets the two directly. I used a gameobject.find before, but even then it only found one, the one it was supposed to. Now I dont use that, and it still emits from both the faucet and the gun.
Also it would be nice to know if there is a way to use two different fluid materials at the same time? Right now the camera seems to decide which material the fluid has, rather than the emitters and the particle renderes on them.
Hi there.
If you're using <3.4, you need to call fluidRenderer.SetupFluidRenderingCommandBuffer() after adding new particle renderers to the fluid renderer. In 3.4 this is not necessary (when having AutoUpdate enabled in the fluid renderer).
Regarding the faucet and the gun emitting at the same time, make sure the emitter shapes reference the appropriate emitters. You might have both shapes referencing the same emitter.
To use two )or more) different fluid materials at the same time, add two FluidRenderers to the same camera, each one referencing the appropriate particle renderer. Then give each one its own fluid material.
cheers,
|