Shader.Root

導入

v5.0

詳細

シェーダツリーのルート(MaterialLight、またはCameraなど)を戻します。

C#構文

// get accessor

Object rtn = Shader.Root;

JScript の例

/*

	This example shows how to find the material from a shader even when the

	shader is buried deeply in a shader tree.

*/

// Create an object with a texture shader

newscene(null,false);

var root = Application.ActiveProject.ActiveScene.Root;

var model = root.AddModel();

model.name = "MyModel";

var sphere = model.AddGeometry( "Sphere", "MeshSurface" );

var grid = model.AddGeometry( "Grid", "MeshSurface" );

var col = XSIFactory.CreateObject("XSI.Collection");

col.add(sphere);

col.add(grid);

BlendInPresets( "Image", col, false, false );

CreateProjection( col, siTxtSpherical, siTxtDefaultSpherical, "TxtSupport", "TxtProjection" );

var filename = Application.InstallationPath( siFactoryPath ) + 

	"\\Data\\XSI_SAMPLES\\Pictures\\xsilogo.jpg";

var imageclip = CreateImageClip( filename, "XSILogo" );

// Set up the texture space on texture shader

var mat = sphere.Material;

var textureshader = sphere.Material.CurrentTexture;

// Set the texturespace parameter

textureshader.parameters("tspace_id").Value = "TxtProjection";

textureshader.parameters("tex").Connect(imageclip);

// Select the texture shader

SelectObj("MyModel.sphere.Scene_Material.Phong.ambient_blend.Image", null, null);

// Get the sphere from the selection list

var obj = selection(0);

// Set up the sharee material with a specific txtuv for the sphere.

if ( obj.isclassof( siShaderID ) )

{

	var tspace_id = obj.parameters("tspace_id");

	var tex = obj.parameters("tex");

	if ( tspace_id && tex )

	{

		// If the object has a texture shader then change the

		// material hardware display settings to explicitly

		// track the shader's texture uvws and image clip

		// Get material from shader

		var mat = obj.Root;

		// A material may be used by many objects, just pick the first one

		// with a uvw and image clip setting

		var eUsedBy = new Enumerator(mat.usedby);

		for ( ; !eUsedBy.atEnd(); eUsedBy.moveNext() )

		{

			var curObj = eUsedBy.item();

			var uvw = tspace_id.getinstancevalue( curObj, true );

			var imageclip = tex.source;

			if ( uvw && imageclip )

			{

				mat.parameters("TextureSel").value = 3; // Specific TxtUVW & ImageClip

				mat.parameters("UV").setinstancevalue( curObj, uvw );

				mat.parameters("ImageClipName").value = imageclip.name;

			}	

		}

	}

}

// Log the hardware display settings for txtuvw on the scene material

mat = ActiveSceneRoot.Material;

var eUsedBy = new Enumerator(mat.usedby);

var uvparam = mat.parameters("UV");

for ( ; !eUsedBy.atEnd(); eUsedBy.moveNext() )

{

	var curObj = eUsedBy.item();

	var uvwObj = uvparam.getinstancevalue( curObj, true );

	var uvwval = "\"\"";

	if (uvwObj!=null)

		uvwval = uvwObj.fullname;

	logmessage( mat.fullname + " " + curObj.fullname + " " + uvwval );

}

//INFO : Scene_Material MyModel.sphere MyModel.sphere.polymsh.cls.Texture_Coordinates_AUTO.TxtProjection

//INFO : Scene_Material MyModel.grid ""