Notifications
Clear all

[Closed] Plugins – How to write?

I have already included this header files. Can there be another reason that it doesn’t work?
ps: I cant find that chapter in the SDK.

1 Reply
(@spider853)
Joined: 10 months ago

Posts: 0

Float:: not FLOAT::

USE THE 2009 SDK CHM

Ok now it works but when I call the function in maxscript I get the error: Memory allocation error (re)sizing array. This happens in the code line vl.Array[i].append(aTempNumber) if the inner loop runs a second time.

1 Reply
(@spider853)
Joined: 10 months ago

Posts: 0

I’m not sure why, maybe bad implementation I can’t test it right now, but there is another solution to use 1D array is 2D…

basically you write the array as this:

for (int i = …)
for (int j = …_
Array->Append(pos[i][j]);

then access it as
for (int i = …)
for (int j = …_
pos[i][j] = i * nrCols + j

you can get the chm doc here http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=7481368

I have tried now this code for a one dimensional array. But it doesn’t work either. 3ds Max closes when i call Test(5);:
def_visible_primitive(Test,“Test”);
Value* Test_cf(Value** arg_list, int count)
{
check_arg_count(Test,1,count);
type_check(arg_list[0],Integer,“Error”);
float testarray[2];
testarray[0] = 1;
testarray[1] = 4;
one_typed_value_local(Array* rArray); vl.rArray = new Array (2); for (int i = 0 ; i <= 2 ; i++) { Value* aTempNumber = Float::heap_intern(testarray[i]); vl.rArray->append(aTempNumber); } return_value(vl.rArray);

float testarray[2];

vl.rArray = new Array (2); for (int i = 0 ; i <= 2 ; i++)

out of bounds

Here is a peace of code from my SPH simulation for scripting plugin


Value* SetupParticles_cf(Value **arg_list, int count)
{
 check_arg_count(UpdateParticles, 6, count);
 for (int i = 0; i < count; i++) {
  if (!is_float(arg_list[i])) {
   throw RuntimeError("Need 6 floats!!");
   break;
  }
 }
h = arg_list[0]->to_float(); //dist
Rho0 = arg_list[1]->to_float(); //Rho0
k = arg_list[2]->to_float(); //spring constant
kNear = arg_list[3]->to_float();
sigma = arg_list[4]->to_float();
beta = arg_list[5]->to_float();
 
 
/*
float sigma = 0.02;
float beta = 0.01;
float kSpring = 0.5;
float yConst = 0.2;
float Lconst = 5;
float alpha = 0.3;
*/
 return &ok; 
}
Value* GetUniqueIDs_cf(Value **arg_list, int count)
{
 check_arg_count(UpdateParticles, 0, count);
 one_typed_value_local(Array* rArray); 
 vl.rArray = new Array (Particles.size()); 
 
   map<int, Particle>::iterator pIt;
	 for (pIt = Particles.begin(); pIt != Particles.end(); pIt++) {
   Value* tmpID = Integer::heap_intern(pIt->first); 
  vl.rArray->append(tmpID); 
   } 
   return_value(vl.rArray); 
}
Value* GetVelocities_cf(Value **arg_list, int count)
{
 check_arg_count(UpdateParticles, 0, count);
  one_typed_value_local(Array* rArray); 
 vl.rArray = new Array (Particles.size()); 
 
   map<int, Particle>::iterator pIt;
	 for (pIt = Particles.begin(); pIt != Particles.end(); pIt++) {
   Value* tmpVel = new Point3Value(pIt->second.vel); 
  vl.rArray->append(tmpVel); 
   } 
   return_value(vl.rArray); 
}
 

but I’m looking now at this line
Value* tmpVel = new Point3Value(pIt->second.vel);
and not sure if its good…
if Value gets GC then good, else its needs to register it for GC, or I need to free it after append

a better aproach could be instead of one_typed_Value_local to use
two_typed_value_locals and register some var for Point3Value so it will be visible to GC

Thanks a lot. a float array works now, but I have the problem that Value* temp = new Point3Value(a) does not work. a is a value of type Point3. Is there a special header file for Point3Value? The error message is: error: syntax error: identifier: Point3Value

1 Reply
(@spider853)
Joined: 10 months ago

Posts: 0

Do you need that Point3?
Its an example from my plugin.

#include “maxscrpt/3DMath.h”

Yes I need that. Thanks a lot

Page 3 / 3