[Closed] Append sub-arrays of diferent sizes into an array ?
Hello all, I have a new question about how to append arrays with sub-array… in a special case…
I have thoses two array …
MyBonesPerVert #(3, 2) and myVertexWeight#(0.105833, 0.788333, 0.105833, 0.839333, 0.160667)
And I want this :myWeightPerVertList#(#(0.105833, 0.788333, 0.105833), #(0.839333, 0.160667))
Here I am so far
myWeightPerVertList = #()
for BonNo = 1 to MyBonesPerVert.count do
(
myBoneNumber = MyBonesPerVert[BonNo]
for vert = 1 to myVertexWeight.count by myBoneNumber do
(
append myWeightPerVertList #(myVertexWeight[vert],myVertexWeight[vert+1] ) --==> here's the obvious issue I see
)
myWeightPerVertList
)
I simply don’t find how to append my array! help please !
Blobynator
this example should help you to understand how collect array of arrays, and it might be also helpful for what you are trying to do (Skin? ;))
fn getSkinVertData =
(
if iskindof (sk = modpanel.getcurrentobject()) Skin do
(
for v=1 to skinops.getNumberVertices sk collect
(
bones = #()
weights = #()
for k=1 to skinops.GetVertexWeightCount sk v do
(
append bones (skinops.GetVertexWeightBoneID sk v k)
append weights (skinops.GetVertexWeight sk v k)
)
#(bones, weights)
)
)
)
And one more example with values only
MyBonesPerVert = #(3, 2, 4)
MyVertexWeight = #(0.105833, 0.788333, 0.105833, 0.839333, 0.160667, 0.123, 0.256, 0.5698, 0.58979)
fn makeSubArr arrVals: subsCnt: =
(
local resultArr = #()
for j in subsCnt do
(
tmpArr = #()
for i = 1 to arrVals.count where i < j+1 do (append tmpArr arrVals[1] ; deleteItem arrVals 1)
append resultArr tmpArr
) ; resultArr
)
makeSubArr arrVals:MyVertexWeight subsCnt:MyBonesPerVert
--> #(#(0.105833, 0.788333, 0.105833), #(0.839333, 0.160667), #(0.123, 0.256, 0.5698, 0.58979))
Thanks both of you : )
You’ve solve my current problem… and my next in one shot : )
Actually, I’d be greatfull if I could have a tiny explanation about how works the second example ? I have well integrated it in my script, it works well, and I know I could use it for similar cases but I am a bit frustrated not understand it plainly. Especially the loop part and why I cant have this last bit ” RSTA_SortVertWeight arrVals:MyVertexWeight subsCnt:MyBonesPerVert ” inside the function itself… which would be easier to use then in my tool…
Thanks !
What about for-loop and which one?
Yup. You can use “RSTA_SortVertWeight” as function name
In next example I added more values for spliting where sum is greather the actual array items count. Process stops when arrVals count == 0.
MyBonesPerVert = #(3, 2, 5, 6)
MyVertexWeight = #(0.105833, 0.788333, 0.105833, 0.839333, 0.160667, 0.123, 0.256, 0.5698, 0.58979)
fn RSTA_SortVertWeight arrVals: subsCnt: =
(
local resultArr = #()
for j in subsCnt while arrVals.count > 0 do
(
tmpArr = #()
for i = 1 to arrVals.count where i <= j do (append tmpArr arrVals[1] ; deleteItem arrVals 1)
append resultArr tmpArr
) ; resultArr
)
-- and then execute like this
RSTA_SortVertWeight arrVals:MyVertexWeight subsCnt:MyBonesPerVert