1 | #include "modelgeoclass.h" |
---|
2 | #include "modelgeometryinfo.h" |
---|
3 | #include <frams/vm/classes/collectionobj.h> |
---|
4 | #include <frams/vm/classes/3dobject.h> |
---|
5 | |
---|
6 | #define FIELDSTRUCT ModelGeometry |
---|
7 | static ParamEntry modelgeo_paramtab[]= |
---|
8 | { |
---|
9 | {"Creature: Geometry",1,5,"ModelGeometry", |
---|
10 | "Example usage:\n" |
---|
11 | "Simulator.print(ModelGeometry.forModel(Model.newFromString(\"//0\\np:sh=1\\n\")).area());\n" |
---|
12 | "ModelGeometry.geodensity refers to the global simulator parameter (also available in GUI).\n" |
---|
13 | "Local geodensity of individual ModelGeometry objects can also be changed, like this:\n" |
---|
14 | "var mg=ModelGeometry.forModel(GenePools[0][0].getModel()); mg.geodensity=2; GenePools[0][0].user1=mg.area();\n"}, |
---|
15 | {"geodensity",0,0,"Density","f 0.01 100.0 1.0",FIELD(density),"Affects the geometry calculation precision"}, //note: geodensity instead of density to make the name more unique - because of the unfortunate sim_params merging all configuration fields in a single namespace |
---|
16 | {"forModel",0,PARAM_USERHIDDEN,"","p oModelGeometry(oModel)",PROCEDURE(p_formodel),"The returned ModelGeometry object can be used to calculate geometric properties of the associated model (volume, area, sizes). The density is copied from the current global ModelGeometry.geodensity on object creation."}, |
---|
17 | {"volume",0,PARAM_NOSTATIC|PARAM_USERHIDDEN,"volume","p f()",PROCEDURE(p_volume),}, |
---|
18 | {"area",0,PARAM_NOSTATIC|PARAM_USERHIDDEN,"area","p f()",PROCEDURE(p_area),}, |
---|
19 | {"sizesAndAxes",0,PARAM_NOSTATIC|PARAM_USERHIDDEN,"sizesAndAxes","p oVector()",PROCEDURE(p_sizesandaxes),"The returned vector contains XYZ (sizes) and Orient (axes) objects."}, |
---|
20 | |
---|
21 | {0,0,0,}, |
---|
22 | }; |
---|
23 | #undef FIELDSTRUCT |
---|
24 | |
---|
25 | ExtObject ModelGeometry::makeDynamicObject(ModelGeometry* mg) |
---|
26 | {return ExtObject(&mg->par,mg);} |
---|
27 | |
---|
28 | ModelGeometry::ModelGeometry(ModelObj *mo) |
---|
29 | :par(modelgeo_paramtab,this) |
---|
30 | { |
---|
31 | model=mo; |
---|
32 | if (model!=NULL) |
---|
33 | model->incref(); |
---|
34 | } |
---|
35 | |
---|
36 | ModelGeometry::~ModelGeometry() |
---|
37 | { |
---|
38 | if (model!=NULL) |
---|
39 | model->decref(); |
---|
40 | } |
---|
41 | |
---|
42 | void ModelGeometry::p_formodel(ExtValue *args,ExtValue *ret) |
---|
43 | { |
---|
44 | Model *m=ModelObj::fromObject(*args); |
---|
45 | if (m!=NULL) |
---|
46 | { |
---|
47 | ModelGeometry *mg=new ModelGeometry((ModelObj*)m); |
---|
48 | mg->density=density; |
---|
49 | ret->setObject(ModelGeometry::makeDynamicObject(mg)); |
---|
50 | } |
---|
51 | else |
---|
52 | ret->setEmpty(); |
---|
53 | } |
---|
54 | |
---|
55 | void ModelGeometry::p_volume(ExtValue *args,ExtValue *ret) |
---|
56 | { |
---|
57 | ret->setDouble(ModelGeometryInfo::volume(*model,density)); |
---|
58 | } |
---|
59 | |
---|
60 | void ModelGeometry::p_area(ExtValue *args,ExtValue *ret) |
---|
61 | { |
---|
62 | ret->setDouble(ModelGeometryInfo::area(*model,density)); |
---|
63 | } |
---|
64 | |
---|
65 | void ModelGeometry::p_sizesandaxes(ExtValue *args,ExtValue *ret) |
---|
66 | { |
---|
67 | Pt3D sizes; Orient axes; |
---|
68 | ModelGeometryInfo::findSizesAndAxesOfModel(*model,density,sizes,axes); |
---|
69 | VectorObject* n=new VectorObject; |
---|
70 | n->data+=new ExtValue(Pt3D_Ext::makeDynamicObject(sizes)); |
---|
71 | n->data+=new ExtValue(Orient_Ext::makeDynamicObject(new Orient_Ext(axes))); |
---|
72 | ret->setObject(n->makeObject()); |
---|
73 | } |
---|