POV-ray でシーンを作成しようとしています。同じタイプの複数のオブジェクトを作成したいのですが、位置、回転、色が異なります。私が作りたいオブジェクトは次のようになります
#declare Width = 30;
#declare Length = 120;
#declare Thickness = 4;
#declare TipHeight = 17;
// Single Beam------------
#declare Beam = union{
// beam
box {
<-Width/2, TipHeight, 0>,
< Width/2, TipHeight+Thickness, Length>
}
//Triangle head
prism { TipHeight TipHeight+Thickness , 4
<-Width/2, Length>,
< Width/2, Length>,
< 0, Length+Length/8>,
<-Width/2, Length>
}
// tip
cone {
<0, 0, Length>, 0
<0, TipHeight, Length>, TipHeight/2
}
}
次に行うことは、これらのビーム オブジェクトをいくつか作成することです。
// Sine formed beams--------------
#declare EndValue = 20;
#declare MaxTranslation = 100;
#declare MaxRotation = 10; //degrees
#declare BeamsSine = union{
#for (Cntr, 0, EndValue, 1)
#local NormalizedValue = Cntr/EndValue;
object {Beam
rotate y*90
rotate -z*sin(NormalizedValue*2*pi)*MaxRotation
translate z*NormalizedValue*MaxTranslation
texture { pigment {
color Gray
}
}
}
#end
}
#include colors.inc
最初に追加して、
object{ BeamsSine no_shadow }
light_source { <500, 50, 300> color White}
camera {
location <400, 100, 300>
look_at <0, 0, 0>
}
最後に、最小の実例があります。
ここで質問があります。グラデーションを適用して、ビーム オブジェクトのティップ コーンの色を変更したいと考えています。問題は、正弦関数 (傾斜角を決定するために使用される) の値に応じて勾配をシフトする必要があることです。
オブジェクト指向プログラミングから、次のようなものを書きます
class MYBEAM(position):
...make the beam
cone {
<0, 0, Length>, 0
<0, TipHeight, Length>, TipHeight/2
pigment{ gradient{cmap_depending_on_variable_"position"} }
}
次に、各オブジェクトを次のように作成します
for i = 1:10
pos = calculate_position_function(i)
MYBEAM(pos)
...
end
POV-rayでこれを行う方法がわかりません! 追加の引数をビーム オブジェクトに渡すことができません。私が考えることができる唯一の方法は、関数宣言メソッドを使用することですが、オブジェクトを返すことはできませんか? (フロートを返すようにすることしかできません)。
また、オブジェクトの定義の前に変数を作成し、新しいオブジェクトが作成さ#declare mypos = 55;
れる前と同じように再定義して、ループごとに変数を更新しようとしました。#declare mypos = calculate_position_function(i)
これも機能しません (常に最初の位置を使用します...)。
誰でも私の問題に対するアイデア/解決策を持っていますか?