Model.Sources

説明

モデル内にあるすべてのソースオブジェクトのコレクションを戻します。現在のところ、モデルで使用できるソースはActionSourceタイプのみです。これは特殊な種類のSourceオブジェクトです。

オーディオおよび Scene のソース(これらは基本的にオーディオおよびイメージファイルへの参照です)は、すべて Scene.ExternalFiles コンテナの下に格納されます(「Image」を参照)。

注:v6.0 以前では、リファレンスモデルへの変更を管理する方法と同様にモデルソースもこのプロパティを使用して取得できましたが、この機能はDeltaシステムで提供されるようになりました。

C#構文

// get accessor

DataSourceCollection rtn = Model.Sources;

JScript の例

/*

	This example demonstrates how to find all sources in the scene

	by using the Model.Sources property on every model returned from

	the X3DObject.Models property, given this structure:

	    Scene_Root (Model)

	        |- Herb (Model)

	        |    |- Mixer		(animation clip on null.posx)

	        |    |- null 		(null.size = FCurve)

	        |

	        |- Jesse (Model)

	        |    |- Mixer		(animation clips on null.scly,null.sclz,null.rotz)

	        |    |- null

	        |

	        |- Sally (Model)

	             |- Mixer		(audio clip)

	             |- grid		(image on its texture projection)

*/

function FindSourcesUnderModel( in_model )

{

	// We will return a comma-delimited string of the names of all sources found 

	var foundsrcs = "";

	Application.LogMessage( "\n\tSearching " + in_model.FullName + " for sources...", siComment );

	// Loop through the collection of sources found under this model to print the

	// name and add its name to the result string

	if ( in_model.Sources.Count > 0 ) {

		var s = new Enumerator( in_model.Sources );

		for ( ; !s.atEnd(); s.moveNext() ) {

			var src = s.item();

			Application.LogMessage( "\t" + src.FullName + " is a " + ClassName(src), siComment );

			// Shorthand for making sure we don't add an extra comma to the start of the list

			foundsrcs += ( foundsrcs == "" ) ? src.FullName : "," + src.FullName;

		}

	} else {

		Application.LogMessage( "\tNo sources found on " + in_model.FullName, siComment );

	}

	// Return empty strings too; the caller will handle testing for no data

	return foundsrcs;

}

// Set up the scene (see end of example for details)

SetTheScene();

// Search through all models in the scene for sources

var models = new ActiveXObject( "XSI.Collection" );

models.AddItems( ActiveSceneRoot.Models(true) );

models.Add( ActiveSceneRoot );

Application.LogMessage( "SEARCHING MODELS: " + models.GetAsText(), siComment );

// Build a collection of sources

var sources = new ActiveXObject( "XSI.Collection" );

for ( var m=0; m<models.Count; m++ ) {

	var results = FindSourcesUnderModel( models(m) );

	if ( results != "" ) { 

		sources.AddItems(results); 

	}

}

// Now this source collection contains all sources in the scene,

// regardless of which model they are under

Application.LogMessage( "\nFINAL SCORE: Found " + sources.Count + " sources: ", siComment );

Application.LogMessage( sources.GetAsText(), siComment );

// And just for bonus marks, get the list of external files

var extfiles = ActiveProject.ActiveScene.ExternalFiles;

Application.LogMessage( "\nBONUS: Found " + extfiles.Count + " external file(s)", siComment );

for ( var f=0; f<extfiles.Count; f++ ) {

	Application.LogMessage( "\t" + extfiles(f).ResolvedPath, siComment );

}

// Expected results:

//SEARCHING MODELS: Herb,Jesse,Sally,Scene_Root

//

//	Searching Herb for sources...

//	Sources.Herb.Shuffle is a ActionSource

//

//	Searching Jesse for sources...

//	Sources.Jesse.Zinging is a ActionSource

//	Sources.Jesse.Thwacking is a ActionSource

//

//	Searching Sally for sources...

//	No sources found on Sally

//

//	Searching Scene_Root for sources...

//	No sources found on Scene_Root

//

//FINAL SCORE: Found 3 sources: 

//Sources.Herb.Shuffle,Sources.Jesse.Zinging,Sources.Jesse.Thwacking

//

//BONUS: Found 2 external file(s)

//	C:\Program Files\Messenger\ONLINE.WAV

//	<factory_path>\Application\rsrc\noIcon.pic

// Helper function to make this example more readable

function SetTheScene()

{

	NewScene( null, false );

	// ~~~~ HERB'S SETUP ~~~~ 

	var herb = ActiveSceneRoot.AddModel();

	herb.Name = "Herb";

	var obj = herb.AddNull();

	// Make the icon a diamond

	obj.primary_icon = 7;

	// Set up an fcurve on the size of the null

	var keys = new Array( 1, 1,  34, 12,  73, 38 );

	obj.size.AddFCurve2( keys );	

	// Set up another fcurve on the null's position in X

	keys = new Array( 3, 0.5,  22, 1.0,  75, 3.5,  80, -2.0 );

	var fc = obj.posx.AddFCurve2( keys );

	// Store the fcurve on posx as an action source

	herb.AddActionSource( "Shuffle", new Array(obj.posx.FullName), 

		new Array(fc), new Array(true) );

	// ~~~~ JESSE'S SETUP ~~~~ 

	var jess = ActiveSceneRoot.AddModel();

	jess.Name = "Jesse";

	obj = jess.AddNull();

	// Create an action source on the null's scaling in Y and Z (fcurves)

	keys = new Array( 5, 1.2,  20, 1.7,  45, 2.0,  90, 2.5 );

	targets = new Array( obj.scly.FullName, obj.sclz.FullName );

	sources = new Array( obj.scly.AddFCurve2(keys), obj.sclz.AddFCurve2(keys) );

	actives = new Array( true, true );

	jess.AddActionSource( "Zinging", targets, sources, actives );

	// Add a rotation source too

	keys = new Array( 6, 0,  36, -30,  99, 0 );

	targets = new Array( obj.rotz.FullName );

	sources = new Array( obj.rotz.AddFCurve2(keys) );

	actives = new Array( true );

	jess.AddActionSource( "Thwacking", targets, sources, actives );

	// ~~~~ SALLY'S SETUP ~~~~ 

	var sal = ActiveSceneRoot.AddModel();

	sal.Name = "Sally";

	obj = sal.AddGeometry( "Grid", "MeshSurface" );

	// Create a grid with a texture projection

	ApplyShader( obj, null, null, siUnspecified, siLetLocalMaterialsOverlap );

	CreateProjection( obj, siTxtSpherical, siTxtDefaultSpherical, "", "Texture_Projection", null, siRelDefault, "" );

	// Applying an image to the texture projection creates an image source

	BlendInTextureLayers( "Image", obj, 1, false, siReplaceAndBlendInPreset, true, true, false, false );

	// Also add an audio source and instantiate it in the mixer

	var aud = ImportAudio( sal, null, "Wavy" );

	AddAudioClip( sal, aud );

}