朱峰社区首页 朱峰社区

搜索资源 注册|登陆

等待

返回 展开菜单
按功能 按软件

Houdini基础

Houdini基础

包含30节视频教程

Houdini是一款功能强大的3D合成软件,曾经效力于300部以上经典电影的特效制作,比如烟火,水等复杂的后期合成都少不了它。

关闭

houdini创建一个数组

关注:150 留言:0 楼主:DanteZ 发帖时间:21年7月23日

DanteZ

普通会员

DanteZ

社区新人:1级

关注562人

  • 性别

  • 年龄

    24

  • 积分

    1

  • 登陆

    1

  • 发帖

    2

间隔线

Array
Overview

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

VEX包含一个数组数据类型。用于以下几处:

  • Supporting ramp parameters. 支持斜坡参数

  • Reading capture data from surface nodes using the import() function.使用import()函数从表面节点读取捕获数据。

  • General programming, wherever arrays would be useful.一般用到数组的编程。

Note

Currently VEX does not support multi-dimensional arrays.目前,VEX不支持多维数组。

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

这个例子展示了你可以用数组做的一些疯狂的事情:

  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 声明数组类型

To declare an array variable, the general form is  要声明数组变量,一般的形式是

 member_type var_name[]:

  1. // my_array is an array of floats ----my_array是一个浮点数数组
  2. float my_array[];
  3. // v is a single vector, vector_array is an array of vectors ----v是一个向量,vector_array是一个向量数组
  4. vector v, vector_array[];
  5. // str_array is an array of strings str_array ---是一个字符串数组
  6. string str_array[];

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

您可以选择将大小放在方括号中,但是VEX编译器目前会忽略它。

To declare a function that returns an array:

声明一个返回数组的函数:

  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:

声明返回数组的嵌套函数:

  1. // A function which returns an array of vectors--返回向量数组的函数
  2. cvex
  3. foo()
  4. {
  5. // Use the optional 'function' keyword to avoid type ambiguity--函数使用可选的“function”关键字来避免类型歧义
  6. function vector[] rgb_array()
  7. {
  8. ...
  9. };
  10. }

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

若要指定内容数组,请使用大括号,数组成员之间用逗号分隔:

  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:

如果你指定标量,其中一个向量是预期的,编译器分配标量值给向量的所有组件:

  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() 函数的作用是:从数组的参数中创建一个数组。

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()生成任何类型的数组。强制array()生成向量(例如):

vector (array (value1, value2, ...) );
Accessing and setting array values
访问和设置数组值

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

使用arrayname[index]根据值在数组中的位置查找值。

  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 "".

数组边界在运行时检查。读取超出数组范围时将返回0或“”。这可能在将来生成警告或可选的运行时错误。写入数组末尾后,将调整数组大小以包含写入的索引。新条目将被设置为0或“”。

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

使用python风格的索引。这意味着负索引指的是数组末尾的位置,从1开始倒着数的位置,最后一位是 -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:

你也可以使用方括号符号赋值:

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

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

getcomp和setcomp函数是使用方括号符号的等价函数。比如:getcomp(array[], int index)  取array[]中下标为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];

方括号运算符也适用于向量。您可以将它与矩阵一起使用,也可以使用一对括号:float a = m3[0][1];

Slicing Arrays 分割数组

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

方括号可用于使用Python切片符号提取子数组。详见: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.

对于使用基于切片的方括号符号,slice函数是等效的。

Copying between arrays and vectors/matrices
数组和向量/矩阵之间的复制

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

赋值运算符支持在向量类型和浮点数组之间赋值:

  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.

如果数组不够长,不足以填充向量/矩阵,则根据需要重复最后一个成员。

  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的数组之间分配:

  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.

下面的函数允许查询和操作数组。

resize

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

设置数组的长度。如果数组被放大,中间值将为0或“”。

len

Returns the length of an array. 返回数组的长度

pop

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

从数组中删除最后一项(将数组大小减少1)并返回它。

push

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

将项添加到数组末尾(将数组大小增加1)。

getcomp

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

获取与array[num]相同的数组元素的值。

setcomp

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

设置数组组件的值,与array[num] = value相同。

array

Efficiently creates an array from its arguments.

有效地根据它的元素创建数组。

serialize

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

将一组向量或矩阵展开成一组浮点数。

unserialize

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

反转序列化的效果:将浮点数的平面数组组装成向量或矩阵数组。

neighbours

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

一个基于数组的对neighborcount /neighbour组合的替换。返回给定点的相邻点的点编号数组。

In addition, the following functions work with arrays:

此外,以下函数可以处理数组:

  • min 返回数组中的最小值。

  • avg 返回输入值的平均值 ---返回数组中值的平均值。

  • spline 沿着折线或样条曲线采样一个值。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允许您为一组参数指定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不支持多维数组。

  • Arrays cannot be passed between shaders (through simport, etc.). 数组不能在着色器之间传递

  • Arrays cannot be written to image planes. 数组不能写入图像平面。


赞0 踩0

未知用户

2005-2021 朱峰社区 版权所有 辽ICP备2021001865号-1
2005-2021 ZhuFeng Community All Rights Reserved

VIP

朱峰社区微信公众号

回顶部

1.复制文本发给您的QQ好友或群、微信等;好友点击链接以后,转发就成功了。 2.如朋友点击您的链接,您需要需刷新一下才行;同一个好友仅能点击一次。
购买VIP,观看所有收费教程!!