Jump to content

[SOLVED] Accessing the ObjectSky class from a Node


photo

Recommended Posts

Hi there,

 

To control the weather in a scenery, I'm using the following code. Like this I can control the height of the clouds received by a Cigi packet.

 

Now, I want to control the clouds in depth, slice, density, etc from the ObjectSky class. But I don't see how to get to this derived class to apply their methods.

Node clMiddle = engine.world.getNode(id);
if (clouds == NULL) {
	log.message("getNode(clMiddle) failed\n");
}

clMiddle.setPosition(dvec3(0.0, 0.0, clBase));
Link to comment

Hello Paul,

Just use node_cast like in this code sample:

// make sure that node with id is definitely ObjectSky
sky = node_cast(engine.world.getNode(id));

You can also cast manually like this:

// make sure that node with id is definitely ObjectSky
Node node = engine.world.getNode(id);
ObjectSky sky = ObjectSky(node);

Here's safe version of cast:

Node node = engine.world.getNode(id);
if(node != NULL && node.getType() == NODE_OBJECT_SKY) {
    ObjectSky sky = node_cast(node);
}
Link to comment

Once again, sorry...

 

I can now control all the params of the clouds, as I wished. I also integrated a second cloud layer. And also this one, I can control.

 

But now, the render performance dropped drastically. I changed back the world script file and erased all the controlling commands to the clouds but the render time remains doubled to what I had before.

 

Do I miss a file, where some nodes, meshes, etc. is written? I just doubled the code in the .world file. See below:

		<node type="ObjectSky" id="1" collider="0" name="baseCloudLayer">
			<simulation>1</simulation>
			<size>24000 24000 800</size>
			<min_slices>500</min_slices>
			<max_slices>600</max_slices>
			<distribute>2</distribute>
			<humidity>0.96</humidity>
			<transition>0.5</transition>
			<extinction>0.7</extinction>
			<density_image>washington/textures/environment/clouds.png</density_image>
			<density_velocity>30 30 0</density_velocity>
			<density_offset>1095.54 1095.54 0</density_offset>
			<density_layer>3</density_layer>
			<surface name="sphere" material="sky" property="surface_base">
				<material>
					<blend src="src_alpha" dest="one_minus_src_alpha"/>
					<options post_scattering="1"/>
					<state name="inscattering">1</state>
				</material>
			</surface>
			<surface name="volume" material="sky" property="surface_base">
				<material>
					<blend src="src_alpha" dest="one_minus_src_alpha"/>
					<options post_scattering="1" two_sided="1"/>
					<state name="surface">1</state>
					<state name="inscattering">1</state>
				</material>
			</surface>
			<surface name="shadow" material="sky" property="surface_base">
				<material>
					<blend src="zero" dest="src_alpha"/>
					<options/>
					<state name="surface">2</state>
				</material>
			</surface>
			<transform>1 0 0 0 0 1 0 0 0 0 1 0 0 0 1615.43994140625 1</transform>
		</node>
Link to comment
×
×
  • Create New...