朱峰社區(qū)首頁(yè) 朱峰社區(qū)

搜索資源 注冊(cè)|登陸

等待

返回 展開菜單
按功能 按軟件

Houdini基礎(chǔ)

Houdini基礎(chǔ)

包含30節(jié)視頻教程

(本教程houdini技術(shù)已老請(qǐng)購(gòu)買之后houdini更新課程)Houdini是一款功能強(qiáng)大的3D合成軟件,曾經(jīng)效力于300部以上經(jīng)典電影的特效制作,比如煙火,水等復(fù)雜的后期合成都少不了它。

關(guān)閉

houdini創(chuàng)建一個(gè)數(shù)組

關(guān)注:831 留言:0 樓主:DanteZ 發(fā)帖時(shí)間:21年7月23日

DanteZ

普通會(huì)員

DanteZ

社區(qū)新人:1級(jí)

關(guān)注1674人

  • 性別

  • 年齡

    24

  • 積分

    1

  • 登陸

    1

  • 發(fā)帖

    2

間隔線

Array
Overview

VEX includes an array datatype. This is useful in several places:

VEX包含一個(gè)數(shù)組數(shù)據(jù)類型。用于以下幾處:

  • Supporting ramp parameters. 支持斜坡參數(shù)

  • Reading capture data from surface nodes using the import() function.使用import()函數(shù)從表面節(jié)點(diǎn)讀取捕獲數(shù)據(jù)。

  • General programming, wherever arrays would be useful.一般用到數(shù)組的編程。

Note

Currently VEX does not support multi-dimensional arrays.目前,VEX不支持多維數(shù)組。

This example shows off some of the crazy things that you can do with arrays:

這個(gè)例子展示了你可以用數(shù)組做的一些瘋狂的事情:

  1. surface
  2. crazy(
  3. string maps[] = { "Mandril.rat", "default.pic" };
  4. export float alength = 0;
  5. )
  6. {
  7. vector texclr, av[];
  8. texclr = texture(maps[s+t > 1], s, t);
  9. av = array( {1,0,0}, vector(nrandom()), t, texclr, {.5,0,0});
  10. if (fit(noise(s*8), 0, 1, .3, .7) > t)
  11. av = array(1, {0,1,0}, 0);
  12. Cf = spline("linear", s, av);
  13. alength = len(av);
  14. }
Declaring array types 聲明數(shù)組類型

To declare an array variable, the general form is  要聲明數(shù)組變量,一般的形式是

 member_type var_name[]:

  1. // my_array is an array of floats ----my_array是一個(gè)浮點(diǎn)數(shù)數(shù)組
  2. float my_array[];
  3. // v is a single vector, vector_array is an array of vectors ----v是一個(gè)向量,vector_array是一個(gè)向量數(shù)組
  4. vector v, vector_array[];
  5. // str_array is an array of strings str_array ---是一個(gè)字符串?dāng)?shù)組
  6. string str_array[];

You can optionally put a size inside the square brackets, but the VEX compiler currently ignores it.

您可以選擇將大小放在方括號(hào)中,但是VEX編譯器目前會(huì)忽略它。

To declare a function that returns an array:

聲明一個(gè)返回?cái)?shù)組的函數(shù):

  1. // A function which returns an array of vectors
  2. vector[] rgb_array()
  3. {
  4. ...
  5. };

To declare a nested function that returns an array:

聲明返回?cái)?shù)組的嵌套函數(shù):

  1. // A function which returns an array of vectors--返回向量數(shù)組的函數(shù)
  2. cvex
  3. foo()
  4. {
  5. // Use the optional 'function' keyword to avoid type ambiguity--函數(shù)使用可選的“function”關(guān)鍵字來避免類型歧義
  6. function vector[] rgb_array()
  7. {
  8. ...
  9. };
  10. }

To specify a literal array, use curly braces, with the array members separated by commas:

若要指定內(nèi)容數(shù)組,請(qǐng)使用大括號(hào),數(shù)組成員之間用逗號(hào)分隔:

  1. vector an_array[] = { {1, 2, 3}, {2, 3, 4}, {4, 5, 6} };
  2. vector[] rgb_array()
  3. {
  4. return { {1, 0, 0}, {0, 1, 0}, {0, 0, 1} };
  5. }

If you specify scalars where a vector is expected, the compiler assigns the scalar value to all components of the vector:

如果你指定標(biāo)量,其中一個(gè)向量是預(yù)期的,編譯器分配標(biāo)量值給向量的所有組件:

  1. vector an_array[] = { 1, 2, 3};
  2. // an_array[] == { {1, 1, 1}, {2, 2, 2}, {3, 3, 3} }

The array() function creates an array from its arguments.

array() 函數(shù)的作用是:從數(shù)組的參數(shù)中創(chuàng)建一個(gè)數(shù)組。

int my_array[] = array(1, 2, 3, 4, 5);

You can use array() to generate an array of any type. To force array() to generate vectors (for example):

可以使用array()生成任何類型的數(shù)組。強(qiáng)制array()生成向量(例如):

vector (array (value1, value2, ...) );
Accessing and setting array values
訪問和設(shè)置數(shù)組值

Use arrayname[index] to look up a value by its position in the array.

使用arrayname[index]根據(jù)值在數(shù)組中的位置查找值。

  1. vector bw[] = { 0, 1 };
  2. // bw[] == { {0, 0, 0}, {1, 1, 1} }
  3. Cf = bw[index];

Array bounds are checked at run time. Reading out of bounds will return 0 or "". This may generate a warning or optional run-time error in the future. Writing past the end of an array will resize the array to include the index written to. The new entries will be set to 0 or "".

數(shù)組邊界在運(yùn)行時(shí)檢查。讀取超出數(shù)組范圍時(shí)將返回0或“”。這可能在將來生成警告或可選的運(yùn)行時(shí)錯(cuò)誤。寫入數(shù)組末尾后,將調(diào)整數(shù)組大小以包含寫入的索引。新條目將被設(shè)置為0或“”。

Python-style indexing is used. This means negative indices refer to positions from the end of the array.

使用python風(fēng)格的索引。這意味著負(fù)索引指的是數(shù)組末尾的位置,從1開始倒著數(shù)的位置,最后一位是 -1。

  1. int nums[] = { 0, 1, 2, 3, 4, 5 };
  2. int n = nums[10]; // Returns 0
  3. int b = nums[-2]; // Returns 4
  4. string strs[] = { };
  5. string s = strs[20]; // Returns ""

You can also assign values using the square brackets notation:

你也可以使用方括號(hào)符號(hào)賦值:

  1. float nums[] = { };
  2. nums[0] = 3.14;

(The getcomp and setcomp functions are equivalents for using the square brackets notation.)

getcomp和setcomp函數(shù)是使用方括號(hào)符號(hào)的等價(jià)函數(shù)。比如:getcomp(array[], int index)  取array[]中下標(biāo)為index的值

Note

The square-brackets operator also works on vectors. You can use it with matrices as well using a pair of brackets: float a = m3[0][1];

方括號(hào)運(yùn)算符也適用于向量。您可以將它與矩陣一起使用,也可以使用一對(duì)括號(hào):float a = m3[0][1];

Slicing Arrays 分割數(shù)組

The square-brackets can be used to extract sub-arrays using the Python slicing notation.

方括號(hào)可用于使用Python切片符號(hào)提取子數(shù)組。詳見:https://blog.csdn.net/qq_41973536/article/details/82690242

  1. int nums[] = { 0, 1, 2, 3, 4, 5 };
  2. int start[] = nums[0:2]; // { 0, 1 }
  3. int end[] = nums[-2:]; // { 4, 5 }
  4. int rev[] = nums[::-1]; // { 5, 4, 3, 2, 1, 0 }
  5. int odd[] = nums[1::2]; // { 1, 3, 5 }

The slice function is the equivalent for using the slice-based square brackets notation.

對(duì)于使用基于切片的方括號(hào)符號(hào),slice函數(shù)是等效的。

Copying between arrays and vectors/matrices
數(shù)組和向量/矩陣之間的復(fù)制

The assignment operator supports assigning values between vector types and arrays of floats:

賦值運(yùn)算符支持在向量類型和浮點(diǎn)數(shù)組之間賦值:

  1. float x[];
  2. // Cf and P are vectors
  3. x = set(P); // Assigns the components of P to the corresponding
  4. // members of the array x
  5. Cf = set(x); // Assigns the first 3 members of x as the
  6. // components of the vector Cf

If the array is not long enough to fill the vector/matrix, the last member is repeated as often as necessary.

如果數(shù)組不夠長(zhǎng),不足以填充向量/矩陣,則根據(jù)需要重復(fù)最后一個(gè)成員。

  1. float x[] = {1, 2} // Not long enough to fill a vector
  2. Cf = set(x); // Cf == {1, 2, 2}

You can also assign between matrix types and arrays of vector2/vector/vector4:

你也可以在矩陣類型和vector2/vector/vector4的數(shù)組之間分配:

  1. vector2 v2[];
  2. vector v[];
  3. vector4 v4[];
  4. matrix2 m2 = 1;
  5. matrix3 m3 = 1;
  6. matrix m4 = 1;
  7. v = set(m3); // Each row of the 3x3 matrix is put into a vector
  8. m3 = set(v); // Copy the vectors into the row vectors of the matrix
  9. v4 = set(m4); // Extract the rows of the matrix into the vector4 array
  10. m4 = set(v4); // Create a matrix using the vector4's in the array as row vectors

In summary: 總之

Left side =Right sideNotes
vector2float[]E.g. vector2 v = {1,2}
vectorfloat[]E.g. vector v = {1,2,3}
vector4float[]E.g. vector4 v = {1,2,3,4};
matrix2float[]E.g. matrix2 m = {1,2,3,4};
matrix2vector2[]E.g. matrix2 m = { {1,2}, {4,5} };
matrix3float[]E.g. matrix3 m = {1,2,3,4,5,6,7,8,9};
matrix3vector[]E.g. matrix3 m = { {1,2,3}, {4,5,6}, {7,8,9}};
matrixfloat[]E.g. matrix m = {1,2,3,4,5,6,7,8,9.., 16};
matrixvector4[]E.g. matrix m = { {1,2,3,4}, {5,6,7,8}, ... {13,14,15,16}};
float[]vector2Create an array of 2 floats from the components
float[]vectorCreate an array of 3 floats from the components
float[]vector4Create an array of 4 floats from the components
float[]matrix2Create an array of 4 floats from the matrix2
vector2[]matrix2Create an array of 2 vector2s from the matrix2
float[]matrix3Create an array of 9 floats from the matrix3
vector[]matrix3Create an array of 3 vectors from the matrix3
float[]matrix4Create an array of 16 floats
vector4[]matrix4Create an array of 4 vector4s.
Looping over an array

See foreach.

Working with arrays

The following functions let you query and manipulate arrays.

下面的函數(shù)允許查詢和操作數(shù)組。

resize

Sets the length of the array. If the array is enlarged, intermediate values will be 0 or "".

設(shè)置數(shù)組的長(zhǎng)度。如果數(shù)組被放大,中間值將為0或“”。

len

Returns the length of an array. 返回?cái)?shù)組的長(zhǎng)度

pop

Removes the last item from the array (decreasing the size of the array by 1) and returns it.

從數(shù)組中刪除最后一項(xiàng)(將數(shù)組大小減少1)并返回它。

push

Adds an item to the end of an array (increasing the size of the array by 1).

將項(xiàng)添加到數(shù)組末尾(將數(shù)組大小增加1)。

getcomp

Gets the value of an array component, the same as array[num].

獲取與array[num]相同的數(shù)組元素的值。

setcomp

Sets the value of an array component, the same as array[num] = value.

設(shè)置數(shù)組組件的值,與array[num] = value相同。

array

Efficiently creates an array from its arguments.

有效地根據(jù)它的元素創(chuàng)建數(shù)組。

serialize

Flattens an array of vectors or matrices into an array of floats.

將一組向量或矩陣展開成一組浮點(diǎn)數(shù)。

unserialize

Reverses the effect of serialize: assembles a flat array of floats into an array of vectors or matrices.

反轉(zhuǎn)序列化的效果:將浮點(diǎn)數(shù)的平面數(shù)組組裝成向量或矩陣數(shù)組。

neighbours

An array-based replacement for the neighbourcount/neighbour combo. Returns an array of the point numbers of the neighbors of a given point.

一個(gè)基于數(shù)組的對(duì)neighborcount /neighbour組合的替換。返回給定點(diǎn)的相鄰點(diǎn)的點(diǎn)編號(hào)數(shù)組。

In addition, the following functions work with arrays:

此外,以下函數(shù)可以處理數(shù)組:

  • min 返回?cái)?shù)組中的最小值。

  • avg 返回輸入值的平均值 ---返回?cái)?shù)組中值的平均值。

  • spline 沿著折線或樣條曲線采樣一個(gè)值。http://www.sidefx.com/docs/houdini/vex/functions/spline.html

  • import()

  • addattribute()  http://www.sidefx.com/docs/houdini/vex/functions/addattribute.html

  • metaimport  http://www.sidefx.com/docs/houdini/vex/functions/metaimport.html

VCC pragmas

The ramp pragma lets you specify a ramp user interface for a set of parameters.

ramp pragma允許您為一組參數(shù)指定ramp用戶界面。

#pragma ramp <ramp_parm> <basis_parm> <keys_parm> <values_parm>

See VCC pragmas for more information. http://www.sidefx.com/docs/houdini/vex/pragmas.html

Limitations 局限
  • Currently VEX does not support multi-dimensional arrays.目前,VEX不支持多維數(shù)組。

  • Arrays cannot be passed between shaders (through simport, etc.). 數(shù)組不能在著色器之間傳遞

  • Arrays cannot be written to image planes. 數(shù)組不能寫入圖像平面。


贊0 踩0

未知用戶

2005-2024 朱峰社區(qū) 版權(quán)所有 遼ICP備2021001865號(hào)-1
2005-2024 ZhuFeng Community All Rights Reserved

VIP

朱峰社區(qū)微信公眾號(hào)

回頂部

1.復(fù)制文本發(fā)給您的QQ好友或群、微信等;好友點(diǎn)擊鏈接以后,轉(zhuǎn)發(fā)就成功了。 2.如朋友點(diǎn)擊您的鏈接,您需要需刷新一下才行;同一個(gè)好友僅能點(diǎn)擊一次。
購(gòu)買VIP,觀看所有收費(fèi)教程。