@prefix :        <https://www.web3d.org/x3d/content/examples/Savage/Environment/Atmosphere/CloudsProcedural2.ttl#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema:  <http://schema.org/> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
@prefix x3d:     <https://www.web3d.org/specifications/x3d-4.0.xsd#> .
@prefix x3do:    <https://www.web3d.org/specifications/X3dOntology4.0#> .

:X3D a owl:NamedIndividual, x3do:X3D ;
  x3do:hasHead :head ;
  x3do:hasScene :Scene ;
  x3do:profile 'Immersive' ;
  x3do:version '3.2' ;
  x3do:noNamespaceSchemaLocation 'https://www.web3d.org/specifications/x3d-3.2.xsd' .
:head a owl:NamedIndividual, x3do:head ;
  x3do:hasParent :X3D ;
  x3do:hasMeta :meta_1_1, :meta_1_2, :meta_1_3, :meta_1_4, :meta_1_5, :meta_1_6, :meta_1_7, :meta_1_8, :meta_1_9 .
:meta_1_1 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content 'CloudsProcedural2.x3d' ;
  x3do:name 'title' .
:meta_1_2 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content 'X3D utilizing ecmascript to develop quasi volumetric 3D clouds from png image textured billboard nodes.' ;
  x3do:name 'description' .
:meta_1_3 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content 'Capt Darren W. Murphy' ;
  x3do:name 'creator' .
:meta_1_4 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content '1 November 2007' ;
  x3do:name 'created' .
:meta_1_5 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content '20 October 2019' ;
  x3do:name 'modified' .
:meta_1_6 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content 'https://www.web3d.org/x3d/content/examples/Savage/Environment/Atmosphere/CloudsProcedural2.x3d' ;
  x3do:name 'identifier' .
:meta_1_7 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content 'X3D-Edit, https://www.web3d.org/x3d/content/README.X3D-Edit.html' ;
  x3do:name 'generator' .
:meta_1_8 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content '../../license.html' ;
  x3do:name 'license' .
:meta_1_9 a owl:NamedIndividual, x3do:meta ;
  x3do:hasParent :head ;
  x3do:content 'fix links' ;
  x3do:name 'TODO' .
:meta dcterms:title "CloudsProcedural2.x3d" .
:meta dcterms:description "X3D utilizing ecmascript to develop quasi volumetric 3D clouds from png image textured billboard nodes." .
:meta dcterms:creator "Capt Darren W. Murphy" .
:meta dcterms:created "1 November 2007" .
:meta dcterms:modified "20 October 2019" .
:meta dcterms:identifier "https://www.web3d.org/x3d/content/examples/Savage/Environment/Atmosphere/CloudsProcedural2.x3d" .
:meta dcterms:generator "X3D-Edit, https://www.web3d.org/x3d/content/README.X3D-Edit.html" .
:meta dcterms:license "../../license.html" .
:Scene a owl:NamedIndividual, x3do:Scene ;
  x3do:hasParent :X3D ;
  x3do:hasChildren :WorldInfo_2_1, :Viewpoint_2_2, :Viewpoint_2_3, :Viewpoint_2_4, :Background_2_5, :DirectionalLight_2_6, :Terrain, :Placemarks, :Clouds .
:WorldInfo_2_1 a owl:NamedIndividual, x3do:WorldInfo ;
  x3do:hasParent :Scene ;
  x3do:title 'CloudsProcedural2.x3d' .
:Viewpoint_2_2 a owl:NamedIndividual, x3do:Viewpoint ;
  x3do:hasParent :Scene ;
  x3do:description 'Main' ;
  x3do:jump false ;
  x3do:orientation ( 0 1 0 1.57 ) ;
  x3do:position ( 50000 1000 42000 ) .
:Viewpoint_2_3 a owl:NamedIndividual, x3do:Viewpoint ;
  x3do:hasParent :Scene ;
  x3do:description 'Light House Tower' ;
  x3do:jump false ;
  x3do:orientation ( 0 1 0 1.3 ) ;
  x3do:position ( 45000 1290 44000 ) .
:Viewpoint_2_4 a owl:NamedIndividual, x3do:Viewpoint ;
  x3do:hasParent :Scene ;
  x3do:description 'centerWest' ;
  x3do:jump false ;
  x3do:orientation ( 0 1 0 2.5 ) ;
  x3do:position ( 48000 1000 20000 ) .
:Background_2_5 a owl:NamedIndividual, x3do:Background ;
  x3do:hasParent :Scene ;
  x3do:groundColor ( 0 0 1 ) ;
  x3do:skyColor ( 0 0 1 ) .
:DirectionalLight_2_6 a owl:NamedIndividual, x3do:DirectionalLight ;
  x3do:hasParent :Scene ;
  x3do:ambientIntensity 1 ;
  x3do:direction ( -1 0 0 ) ;
  x3do:global true .
:Terrain a owl:NamedIndividual, x3do:Group ;
  x3do:hasParent :Scene ;
  x3do:hasChildren :Transform_2_7_1, :Transform_2_7_2 ;
  x3do:DEF 'Terrain' .
:Transform_2_7_1 a owl:NamedIndividual, x3do:Transform ;
  x3do:hasParent :Terrain ;
  x3do:hasChildren :Inline_2_7_1_1 ;
  x3do:scale ( 50 50 50 ) ;
  x3do:translation ( 25000 0 25000 ) .
:Inline_2_7_1_1 a owl:NamedIndividual, x3do:Inline ;
  x3do:hasParent :Transform_2_7_1 ;
  x3do:url '"../../Locations/MontereyBayCalifornia/MontereyBayLargeMesh.x3d" "https://www.web3d.org/x3d/content/examples/Savage/Locations/MontereyBayCalifornia/MontereyBayLargeMesh.x3d" "../../Locations/MontereyBayCalifornia/MontereyBayLargeMesh.wrl" "https://www.web3d.org/x3d/content/examples/Savage/Locations/MontereyBayCalifornia/MontereyBayLargeMesh.wrl"' .
:Transform_2_7_2 a owl:NamedIndividual, x3do:Transform ;
  x3do:hasParent :Terrain ;
  x3do:hasChildren :Shape_2_7_2_1 ;
  x3do:rotation ( 1 0 0 1.57 ) ;
  x3do:translation ( 25000 0 25000 ) .
:Shape_2_7_2_1 a owl:NamedIndividual, x3do:Shape ;
  x3do:hasParent :Transform_2_7_2 ;
  x3do:hasGeometry :Rectangle2D_2_7_2_1_1 ;
  x3do:hasAppearance :Appearance_2_7_2_1_2 .
:Rectangle2D_2_7_2_1_1 a owl:NamedIndividual, x3do:Rectangle2D ;
  x3do:hasParent :Shape_2_7_2_1 ;
  x3do:size ( 77000 55000 ) .
:Appearance_2_7_2_1_2 a owl:NamedIndividual, x3do:Appearance ;
  x3do:hasParent :Shape_2_7_2_1 ;
  x3do:hasTexture :ImageTexture_2_7_2_1_2_1 .
:ImageTexture_2_7_2_1_2_1 a owl:NamedIndividual, x3do:ImageTexture ;
  x3do:hasParent :Appearance_2_7_2_1_2 ;
  x3do:url '"ocean.png" "https://www.web3d.org/x3d/content/examples/Savage/Environment/Atmosphere/ocean.png"' .
:Placemarks a owl:NamedIndividual, x3do:Group ;
  x3do:hasParent :Scene ;
  x3do:hasChildren :Transform_2_8_1 ;
  x3do:DEF 'Placemarks' .
:Transform_2_8_1 a owl:NamedIndividual, x3do:Transform ;
  x3do:hasParent :Placemarks ;
  x3do:hasChildren :Inline_2_8_1_1 ;
  x3do:scale ( 50 50 50 ) ;
  x3do:translation ( 45000 30 44000 ) .
:Inline_2_8_1_1 a owl:NamedIndividual, x3do:Inline ;
  x3do:hasParent :Transform_2_8_1 ;
  x3do:url '"Lighthouse.x3d" "https://www.web3d.org/x3d/content/examples/Savage/Environment/Atmosphere/Lighthouse.x3d" "Lighthouse.wrl" "https://www.web3d.org/x3d/content/examples/Savage/Environment/Atmosphere/Lighthouse.wrl"' .
:Clouds a owl:NamedIndividual, x3do:Group ;
  x3do:hasParent :Scene ;
  x3do:hasChildren :Cumulus, :Cirrus, :Fog, :PixelScript, :DirectionalLight_2_9_5 ;
  x3do:DEF 'Clouds' .
:Cumulus a owl:NamedIndividual, x3do:Transform ;
  x3do:hasParent :Clouds ;
  x3do:DEF 'Cumulus' .
:Cirrus a owl:NamedIndividual, x3do:Transform ;
  x3do:hasParent :Clouds ;
  x3do:DEF 'Cirrus' .
:Fog a owl:NamedIndividual, x3do:Transform ;
  x3do:hasParent :Clouds ;
  x3do:DEF 'Fog' .
:PixelScript a owl:NamedIndividual, x3do:Script ;
  x3do:hasParent :Clouds ;
  x3do:hasField :field_2_9_4_1, :field_2_9_4_2, :field_2_9_4_3 ;
  x3do:DEF 'PixelScript' ;
  x3do:directOutput true ;
  x3do:sourceCode """
ecmascript:


function cumulustranslation() // These values designate the boundary location of the cloud
{
	X = 50000*Math.random();          //  X horizontal range
	Y = 1000 + 300*Math.random();	 //  Y vertical base + range
	Z = 50000*Math.random();         // z horizontal range

	randomt = new String(X+' '+Y+' '+Z);

	return randomt;
	
}



function cumulusscale() // these values scale a cloud within a designated size
{

	maxscale = 1;

	scale = Math.round(9+maxscale*Math.random());
	X = 1.5*scale;
	Y = scale;
	Z = scale;

	randomscale = new String(X+' '+Y+' '+Z);

	return randomscale;
	
}


function cirrustranslation() // These values designate the boundary location of the cloud
{
	X = 50000*Math.random();          //  X horizontal range
	Y = 8000 + 1000*Math.random();	 //  Y vertical base + range
	Z = 50000*Math.random();         // z horizontal range

	randomt = new String(X+' '+Y+' '+Z);

	return randomt;
	
}



function cirrusscale() // these values scale a cloud within a designated size
{

	maxscale = 1;

	scale = Math.round(9+maxscale*Math.random());
	X = 1.5*scale;
	Y = 2*Math.random();
	Z = 1.5*scale;

	randomscale = new String(X+' '+Y+' '+Z);

	return randomscale;
	
}


function cumulussectiontranslation() // These random values place another portion of cumulus type cloud
{

	randomtheta = 6.28319*Math.random();
	randomphi = .7854*Math.random();
	randomradius = 90 + 5*Math.random();//the first whole number should be close to the sectionradius

	X = randomradius*Math.cos(randomtheta)*Math.sin(randomphi);
	Z = randomradius*Math.sin(randomtheta)*Math.sin(randomphi);
	Y = randomradius*Math.cos(randomphi);
	

	randomt = new String(X+' '+Y+' '+Z);

	return randomt;
	
}

function cirrussectiontranslation() // These random values place another portion of cirrus type cloud
{

	randomtheta = 6.28319*Math.random();
	randomphi = .7854*Math.random();
	randomradius = 90 + 5*Math.random();//the first whole number should be close to the sectionradius

	X = randomradius*Math.cos(randomtheta)*Math.sin(randomphi);
	Z = randomradius*Math.sin(randomtheta)*Math.sin(randomphi);
	Y = randomradius*Math.cos(randomphi);
	

	randomt = new String(X+' '+Y+' '+Z);

	return randomt;
	
}


function rotation() // This random value is for the billboard rotation not used in this script
{


	radians = 6.28*Math.random();

	randomr = new String('0 0 1 ' + radians );
	
	
	return randomr;
	
}

function cumulus()
{

maxi = 20;  // number of clouds

maxj = 5; // denotes how many portions affecting the size of the cloud

maxk = 8;  // number of billboards indicating cloud density

sectionradius = 100;  //radius of individual cloud sections





for (var i=0; i < maxi; i++) 
{



CloudStringA = '	Transform {		\n' +
'    scale '+ cumulusscale() + '               	\n' +
'    translation '+ cumulustranslation() + '    \n' +    // cloud placement
'    children [	                                \n';


CloudStringB = new Array();
CloudStringF = new Array();

   	for (var j=0; j < maxj; j++)
   	{

	radius = 0;

	CloudStringB[j]= '  Transform {		    	       \n' +
	'    translation '+ cumulussectiontranslation() + '    \n' +     // section placement
	'    children [	                                       \n';

	
	CloudStringC = new Array();
	image = new String();

      		for (var k=1; k < maxk; k++)  // maxk value denotes how many textured billboards make up the cloud 
      		{


		randomtheta = 6.28319*Math.random();
		randomphi = 1.57079*Math.random();
		radius = radius+(sectionradius/maxk); // radius incremental steps based on billow radius and max billboards

		X = radius*Math.cos(randomtheta)*Math.sin(randomphi);
		Z = radius*Math.sin(randomtheta)*Math.sin(randomphi);
		Y = radius*Math.cos(randomphi);


		if (Y <= 30) //cloud shading and lighting control
  	{	
	image = ' \"CloudTexture1_5.png\" \"https://www.web3d.org/x3d/content/examples/Savage/Environment/Spheretexture.png\" \n';
  	}

  		else
  	{	
	image = ' \"CloudTexture1_4.png\" \"https://www.web3d.org/x3d/content/examples/Savage/Environment/Spheretexture.png\" \n';
  	}

	
		
		Billboardtranslation = new String(X+' '+Y+' '+Z);

		CloudStringC[k] = '	Transform {		                \n' +
		'            translation '+ Billboardtranslation   + '          \n' +     // random billboard placement within radius designated above
		'	  children [	                                        \n' +
		'	      Billboard {	                                \n' +
		'	        axisOfRotation 0 0 0	                        \n' +     // 0 0 0 designates rotation on all axis
		'	        children [	                                \n' +
		'	            Transform {	                		\n' +
		'	              rotation  0 0 0 0 		        \n' +     // a rotation of the individual billboards can be defined
		'	              children [	                        \n' +
		'	                  Shape {	                        \n' +
		'	                    appearance Appearance {	        \n' +
		'				material Material {		\n' +
		'				                }  		\n' +
		'	                      texture ImageTexture {	        \n' +
		'	                        url [ ' + image + ' ]           \n' + 
		'	                      }	                                \n' +
		'	                    }	                                \n' +
		'	                    geometry IndexedFaceSet {	        \n' +     // define type of geometry to texture
		'	                      coordIndex [ 0, 1, 2, 3 ]	        \n' +
		'			      solid FALSE		        \n' +
		'	                      coord Coordinate {	        \n' +
		'	                        point [ 50 50 0,	        \n' +     // define size of the geometry. Here 100 meter 2D square.
		'	                                50 -50 0,	        \n' +
		'	                               -50 -50 0,	        \n' +
		'	                               -50 50 0 ]	        \n' +
		'	                      }	                                \n' +
		'	                    }	                                \n' +
		'	                  }	                                \n' +
		'	              ]	                                        \n' +
		'	            }	                                        \n' +
		'	       ]	                                        \n' +
		'	   }	                                                \n' +
		'      ]	                                                \n' +
		'     }	                                                        \n';      
		

		}

	CloudStringD = CloudStringC.join(' ');

	
	CloudStringE = '   ]	                 \n' +
	'	}	                         \n';

	CloudStringF[j] = CloudStringB[j] + CloudStringD +CloudStringE;


	}

CloudStringG = CloudStringF.join(' ');

CloudStringH = '      ]	                                        \n' +
'     }	                                                        \n' +
'#########################################################      \n';

CloudString = CloudStringA + CloudStringG + CloudStringH;



newNode = Browser.createVrmlFromString(CloudString);
Cumulus.children[i] = newNode[0];


   }

}

function cirrus()

{

maxi = 2;  // number of clouds

maxj = 5; // denotes how many portions affecting the size of the cloud

maxk = 8;  // number of billboards indicating cloud density

sectionradius = 1000;  //radius of individual cloud sections





for (var i=0; i < maxi; i++) 
{



CloudStringA = '	Transform {		 \n' +
'    scale '+ cirrusscale() + '               	 \n' +
'    translation '+ cirrustranslation() + '      \n' +    // cloud placement
'    children [	                                 \n';


CloudStringB = new Array();
CloudStringF = new Array();

   	for (var j=0; j < maxj; j++)
   	{

	radius = 0;

	CloudStringB[j]= '  Transform {		    	      \n' +
	'    translation '+ cirrussectiontranslation() + '    \n' +     // section placement
	'    children [	                                      \n';

	
	CloudStringC = new Array();

      		for (var k=1; k < maxk; k++)  // maxk value denotes how many textured billboards make up the cloud 
      		{


		randomtheta = 6.28319*Math.random();
		randomphi = 1.57079*Math.random();
		radius = radius+(sectionradius/maxk); // radius incremental steps based on section radius and max billboards

		X = radius*Math.cos(randomtheta)*Math.sin(randomphi);
		Z = radius*Math.sin(randomtheta)*Math.sin(randomphi);
		Y = radius*Math.cos(randomphi);
		
		Billboardtranslation = new String(X+' '+Y+' '+Z);

		CloudStringC[k] = '	Transform {		                \n' +
		'            translation '+ Billboardtranslation   + '          \n' +     // random billboard placement within radius designated above
		'	  children [	                                        \n' +
		'	      Billboard {	                                \n' +
		'	        axisOfRotation 0 0 0	                        \n' +     // 0 0 0 designates rotation on all axis
		'	        children [	                                \n' +
		'	            Transform {	                		\n' +
		'	              rotation '  + rotation() + '	        \n' +
		'	              children [	                        \n' +
		'	                  Shape {	                        \n' +
		'	                    appearance Appearance {	        \n' +
		'			    material Material {			\n' +
		'			    }					\n' +
 		'	                      texture ImageTexture {	        \n' +
		'	                        url [\"cloudtexture3.png\" \"https://www.web3d.org/x3d/content/examples/Savage/Environment/cloudtexture1_4.png\" ] \n' +
		'	                      }	                                \n' +
		'	                    }	                                \n' +
		'	                    geometry IndexedFaceSet {	        \n' +     // define type of geometry to texture
		'	                      coordIndex [ 0, 1, 2, 3 ]	        \n' +
		'			      solid FALSE		        \n' +
		'	                      coord Coordinate {	        \n' +
		'	                        point [ 500 500 0,	        \n' +     // define size of the geometry. Here 100 meter 2D square.
		'	                                500 -500 0,	        \n' +
		'	                               -500 -500 0,	        \n' +
		'	                               -500 500 0 ]	        \n' +
		'	                      }	                                \n' +
		'	                    }	                                \n' +
		'	                  }	                                \n' +
		'	              ]	                                        \n' +
		'	            }	                                        \n' +
		'	       ]	                                        \n' +
		'	   }	                                                \n' +
		'      ]	                                                \n' +
		'     }	                                                        \n';      
		

		}

	CloudStringD = CloudStringC.join(' ');

	CloudStringE = '   ]	                 \n' +
	'	}	                         \n';

	CloudStringF[j] = CloudStringB[j] + CloudStringD +CloudStringE;


	}

CloudStringG = CloudStringF.join(' ');

CloudStringH = '      ]	                                        \n' +
'     }	                                                        \n' +
'#########################################################      \n';

CloudString = CloudStringA + CloudStringG + CloudStringH;



newNode = Browser.createVrmlFromString(CloudString);
Cirrus.children[i] = newNode[0];

  }

}


function initialize()

{

cumulus();

cirrus();
}
""" .
:field_2_9_4_1 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :PixelScript ;
  x3do:hasChildren :Cumulus-USE-1 ;
  x3do:accessType 'initializeOnly' ;
  x3do:name 'Cumulus' ;
  x3do:type 'SFNode' .
:Cumulus-USE-1 a owl:NamedIndividual, x3do:Transform ;
  x3do:hasParent :field_2_9_4_1 ;
  owl:sameAs :Cumulus . # DEF matching this USE
:field_2_9_4_2 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :PixelScript ;
  x3do:hasChildren :Cirrus-USE-1 ;
  x3do:accessType 'initializeOnly' ;
  x3do:name 'Cirrus' ;
  x3do:type 'SFNode' .
:Cirrus-USE-1 a owl:NamedIndividual, x3do:Transform ;
  x3do:hasParent :field_2_9_4_2 ;
  owl:sameAs :Cirrus . # DEF matching this USE
:field_2_9_4_3 a owl:NamedIndividual, x3do:field ;
  x3do:hasParent :PixelScript ;
  x3do:accessType 'initializeOnly' ;
  x3do:name 'Fog' ;
  x3do:type 'SFNode' .
:DirectionalLight_2_9_5 a owl:NamedIndividual, x3do:DirectionalLight ;
  x3do:hasParent :Clouds ;
  x3do:ambientIntensity 1 ;
  x3do:color ( 1 0 0 ) ;
  x3do:direction ( -1 -1 0 ) ;
  x3do:global true .
