ChangeVertexColorDatatype

導入

v6.5

詳細

指定された VertexColor プロパティについて、 VertexColorChangeDatatype オペレータを追加します。 頂点カラープロパティは、Short (8 ビット カラー)および Float (32 ビット)というカラーを表す 2 種類の内部データ表現をサポートするようになりました。 RenderMap は 32 ビット カラーを CAV にベークするように設定できますが、CAV もまた、処理後に 8 ビットまたは 32 ビット カラーに変更できます。 これによって、たとえば、ユーザは SDK を使用して 32 ビットの精密なカラーを CAV に書き込んだり CAV から読み出したりすることができます。

Vertex Color Change Datatype オペレータを使用すると、通常は読み取り専用であり、SetValueParameter.Value、または Parameter.PutValue2 などを介して変更することのできない「datatype」パラメータを修正できます。以下の JScript のサンプルは、この原則を示しています。

DesiredDatatype 入力パラメータは必須です。 現在の VertexColor プロパティで既に目的のデータ型を使用している場合は、警告メッセージが記録され、どのオペレータもインストールされません。

通常、このコマンドは、VertexColorChangeDatatype オペレータを適用するために 1 回だけ呼び出すことができます。 その後、「datatype」設定を再度変更する必要がある場合は、このコマンドを使用して別のオペレータを適用するのではなく、現在のオペレータの「desireddatatype」パラメータにアクセスします。 以下の JScript の例が示すように、同じ VertexColor プロパティに複数のオペレータを適用している場合は、必ず現在のオペレータの「desireddatatype」パラメータを修正するように注意してください。

スクリプト構文

oReturn = ChangeVertexColorDatatype( [InputObj], DesiredDatatype, [OutputObjs] );

戻り値

新規作成された Operator を格納する XSICollection

パラメータ

パラメータ タイプ 説明
InputObj 名前による VertexColorClusterProperty、または XSICollection 変更する VertexColor プロパティ

デフォルト値:現在選択されているオブジェクトをメイン グループとして使用

DesiredDatatype Integer 目的のデータ型を指定します。

指定可能な値:

説明:

0 short
1 浮動小数 (32ビット)
OutputObjs Operator オブジェクトの XSICollection XSICollection で新しい Operator を返します。

1. JScript の例

/*

	This example demonstrates how to set the read-only DataType on a VertexColor (CAV) property, including 

	avoiding some of the pitfalls of applying more than one Vertex Color Change Datatype operator.

*/

NewScene( "", false );

var obj = Application.ActiveSceneRoot.AddGeometry( "Cube", "MeshSurface" );

var VtxColors = CreateVertexColorSupport( null, null, obj );

// Get the datatype parameter (on the VertexColor property)

var DataType = VtxColors(0).Parameters("datatype");

Application.LogMessage( "Default DataType: " + DataType.Value );

// The datatype parameter is readonly

try {

	// This will throw an error

	DataType.Value = 1;

} catch(e) {

	Application.LogMessage( "Error on DataType.Value = 1: " + e.description, siWarning );

	try {

		// SetValue will also fail

		SetValue( DataType, 1 );

	} catch(f) {

		Application.LogMessage( "Error on SetValue( DataType, 1 ): " + f.description, siWarning );

	}

}

// Use the VertexColorChangeDatatype operator instead

var DataChgOps1 = ChangeVertexColorDatatype( VtxColors, 1 );

var DesiredDType1 = DataChgOps1(0).Parameters("desireddatatype");

Application.LogMessage( "DataType after 1st operator: " + DataType.Value );

// Now that you have the VertexColorChangeDatatype operator, you can 

// use its DesiredDatatype parameter to toggle back and forth

DesiredDType1.Value = 0;

Application.LogMessage( "Back to default: " + DataType.Value );

DesiredDType1.Value = 1;

Application.LogMessage( "Switched to float again: " + DataType.Value );

// However, if you try to apply another operator, only the last one 

// applied will affect the actual data type

var DataChgOps2 = ChangeVertexColorDatatype( VtxColors, 0 );

var DesiredDType2 = DataChgOps2(0).Parameters("desireddatatype");

Application.LogMessage( "DataType after 2nd operator: " + DataType.Value );

DesiredDType1.Value = 1;

Application.LogMessage( "Changed old operator: " + DataType.Value );

DesiredDType2.Value = 1;

Application.LogMessage( "Changed new operator: " + DataType.Value );

// For the truly cautious, get the last operator applied

var CAVProp = obj.ActivePrimitive.Geometry.VertexColors(0);

var LastChgDataTypeOp;

for ( var i=CAVProp.NestedObjects.Count-1; i>=0; i++ ) {

	if ( CAVProp.NestedObjects.Item(i).Type == "vertexcolorchangedatatype" ) {

		LastChgDataTypeOp = CAVProp.NestedObjects.Item(i);

		break;

	}

}

Application.LogMessage( "LastChgDataTypeOp == DataChgOps1: " + LastChgDataTypeOp.IsEqualTo(DataChgOps1(0)) );

Application.LogMessage( "LastChgDataTypeOp == DataChgOps2: " + LastChgDataTypeOp.IsEqualTo(DataChgOps2(0)) );

var LastDesiredDType = LastChgDataTypeOp.Parameters("desireddatatype");

LastDesiredDType.Value = 0;

Application.LogMessage( "Changed final operator: " + DataType.Value );

// Output:

// INFO : Default DataType: 0

// WARNING : 2011 - Error on DataType.Value = 1: Member not found

// ERROR : 2011-EDIT-SetValue - Member not found

// WARNING : Error on SetValue( DataType, 1 ): Object doesn't support this property or method

// INFO : DataType after 1st operator: 1

// INFO : Back to default: 0

// INFO : Switched to float again: 1

// INFO : DataType after 2nd operator: 0

// INFO : Changed old operator: 0

// INFO : Changed new operator: 1

// INFO : LastChgDataTypeOp == DataChgOps1: false

// INFO : LastChgDataTypeOp == DataChgOps2: true

// INFO : Changed final operator: 0

2. VBScript の例

'

' This example creates a Vertex Color property (CAV) and plays with one of the colors 

' to demonstrate how switching the datatype can affect the color values

'

dim CAVObjs, dtype, chgOp, aColors

NewScene , false

SetDisplayMode "Camera", "constant"

CreatePrim "Sphere", "MeshSurface"

' The VertexColor property is the first element in the returned collection

set CAVObj = CreateVertexColorSupport()(0)

set dtype = CAVObj.Parameters("datatype")

' Print current datatype

Application.LogMessage "CAV datatype = " & dtype.Value

' Change datatype to float and print new datatype

set chgOp = ChangeVertexColorDatatype( CAVObj, 1 )(0)

Application.LogMessage "CAV new datatype = " & dtype.Value

' Set Color 47 (facing front view) to be RGBA ( 0.1 , 0.2 , 0.3, 0.4 )

aColors = CAVObj.Elements.Array

aColors(0,47) = 0.1

aColors(1,47) = 0.2

aColors(2,47) = 0.3

aColors(3,47) = 0.4

CAVObj.Elements.Array = aColors

' Retrieve the color and print it

aColors = CAVObj.Elements.Array

Application.LogMessage "Color 47 is (" & aColors(0,47) & ", " & aColors(1,47) & ", " & aColors(2,47) & ", " & aColors(3,47) & ")" 

' Now switch to short datatype and print it

chgOp.Parameters("desireddatatype").Value = 0		' == SetValue chgOp & ".desireddatatype", 0

Application.LogMessage "CAV last datatype = " & dtype.Value

' Retrieve the color and print it

aColors = CAVObj.Elements.Array

Application.LogMessage "Color 47 is (" & aColors(0,47) & ", " & aColors(1,47) & ", " & aColors(2,47) & ", " & aColors(3,47) & ")" 

'Output

' INFO : CAV datatype = 0

' INFO : CAV new datatype = 1

' INFO : Color 47 is (0.100000001490116, 0.200000002980232, 0.300000011920929, 0.400000005960464)

' INFO : CAV last datatype = 0

' INFO : Color 47 is (9.80392172932625E-02, 0.200000002980232, 0.298039227724075, 0.400000005960464)

関連項目

ApplyOp オペレータ CreateVertexColorSupport