I have a function that grabs a model and moves submeshes into the first 10 then I redo the vertex after I have the submesh pieces where I want them. The reason for this is because I have a model that I want to make sure blends correctly, so I keep all the parts on that one model then depending on what upgrades the user has I pull the submesh I need.
Globals.carmdata = This is a hash table that I use to store what material is assigned to the model in Unity. The reason for this is if you ever try to import a max model into unity3d the materials do not go in order. My understanding is this is a bug in the FBX which means Autodesk has to fix, but hasn’t.
The way I was doing this code before is I was using ArrayList, but the CPU spikes when running my code. I run the same routine for different upgrades and in the end I end up with 15 submesh out of the old 100+ submesh that I start with. So because the CPU spikes up and can stay up there for like 3 seconds I wanted to optimize this part and decided to go with BuiltIn Arrays to hopefully speed up the process, but I ran into an error that I can’t figure out.
I removed the rest of my code and just left this part when I had the ArrayList to narrow down what is causing the CPU to spike.
static var blackc = new int[15];
static var submesh1 = new int[1000]; //1000 will not be the final number. Using 1000 right now for testing.
static var submeshlength = 0;
static var submeshlength = 0;
//black
blackc[blackclength] = 1; blackclength=blackclength+1;
if (Globals.upgrades["c"+number+"_upgrade1"] != 1 Globals.upgrades["c"+number+"_upgrade2"] != 1){
if (Globals.upgrades["c"+number+"_upgrade3"] == 1){
blackc[blackclength] = 2; blackclength=blackclength+1;
} else if (Globals.upgrades["c"+number+"_upgrade3"] == 2){
blackc[blackclength] = 3; blackclength=blackclength+1;
} else if (Globals.upgrades["c"+number+"_upgrade3"] == 3){
blackc[blackclength] = 4; blackclength=blackclength+1;
}
}
for (i=0; i<blackc.length; i++){
if (Globals.carmdata["car"+carmodel+"-"+modelname+"-"+blackc[i]] != null){
s = mesh.GetTriangles(int.Parse(Globals.carmdata["car"+carmodel+"-"+modelname+"-"+blackc[i]].ToString()));
print(s);
print(submesh1);
print(submeshlength);
submesh1[submeshlength] = s;
submeshlength=submeshlength+1;
}
}
The error:
InvalidCastException: Cannot cast from source type to destination type.
Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (System.Object value)
Boo.Lang.Runtime.RuntimeServices.UnboxInt32 (System.Object value)
functions.setupmesh (System.Object model, System.Object number, System.Object carmodel) (at Assets/scripts/functions.js:199)
functions+$loadcar$1753+$.MoveNext () (at Assets/scripts/functions.js:5254)
When I print out s I get:
System.Int32[ ]
When I print out submesh1 I get:
System.Int32[ ]
submeshlength gives me 0
So if s and submesh1 are the same then why won’t it let me store s into submesh1?