1 | #include "modelobj.h"
|
---|
2 | #include <frams/vm/classes/genoobj.h>
|
---|
3 | #include <frams/util/extvalue.h>
|
---|
4 | #include <frams/vm/classes/3dobject.h>
|
---|
5 |
|
---|
6 | #define FIELDSTRUCT ModelObj
|
---|
7 | ParamEntry modelobj_paramtab[] =
|
---|
8 | {
|
---|
9 | { "Model", 1, 22, "Model", },
|
---|
10 | { "se", 0, PARAM_NOSTATIC, "startenergy", "f", FIELD(startenergy), },
|
---|
11 | { "Vstyle", 0, PARAM_NOSTATIC, "Visual style", "s", FIELD(vis_style), "See the \"Visual style definition\" context for more information"},
|
---|
12 |
|
---|
13 | { "geno", 0, PARAM_NOSTATIC | PARAM_READONLY, "Geno", "oGeno", GETONLY(geno), },
|
---|
14 | { "newFromString", 0, 0, "Create a new object", "p oModel(s genotype)", PROCEDURE(p_newfromstring), },
|
---|
15 | { "newFromGeno", 0, 0, "Create a new object", "p oModel(oGeno)", PROCEDURE(p_newfromgeno), },
|
---|
16 | { "newWithCheckpoints", 0, 0, "Create a new object", "p oModel(x Geno object or string genotype)", PROCEDURE(p_newwithcheckpoints), "Creates a Model with the \"Checkpoints\" option enabled. Genotype converters supporting Checkpoints provide a sequence of Models that reflects development stages of the creature (this sequence is used purely for debugging and visualization of phenotype growth/development). Checkpoint Models can be accessed using getCheckpoint(i) for i ranging from 0 to numcheckpoints-1. Models created without the Checkpoint option and Models coming from unsupported converters have numcheckpoints=0." },
|
---|
17 |
|
---|
18 | { "numparts", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Number of parts", "d", GETONLY(numparts), },
|
---|
19 | { "numjoints", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Number of joints", "d", GETONLY(numjoints), },
|
---|
20 | { "numneurons", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Number of neurons", "d", GETONLY(numneurons), },
|
---|
21 | { "numconnections", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Number of neuron connections", "d", GETONLY(numconnections), },
|
---|
22 | { "is_valid", 0, PARAM_READONLY | PARAM_NOSTATIC, "Validity", "d 0 1", GETONLY(is_valid) },
|
---|
23 |
|
---|
24 | { "getPart", 0, PARAM_READONLY | PARAM_USERHIDDEN | PARAM_NOSTATIC, "getPart (static model information)", "p oPart(d index)", PROCEDURE(p_getpart), },
|
---|
25 | { "getJoint", 0, PARAM_READONLY | PARAM_USERHIDDEN | PARAM_NOSTATIC, "getJoint (static model information)", "p oJoint(d index)", PROCEDURE(p_getjoint), },
|
---|
26 | { "getNeuroDef", 0, PARAM_READONLY | PARAM_USERHIDDEN | PARAM_NOSTATIC, "getNeuroDef", "p oNeuroDef(d index)", PROCEDURE(p_getneuro), },
|
---|
27 |
|
---|
28 | { "size_x", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, "Bounding box x size", "f", FIELD(size.x), "(size_x,size_y,size_z) are dimensions of the axis-aligned bounding box of the creature, including imaginary Part sizes (Part.s, usually 1.0). A creature consisting of a single default part has the size of (2.0,2.0,2.0) - twice the Part.s value (like a sphere diameter is twice its radius).\nSee also: Creature.moveAbs" },
|
---|
29 | { "size_y", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, "Bounding box y size", "f", FIELD(size.y), "See Model.size_x" },
|
---|
30 | { "size_z", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, "Bounding box z size", "f", FIELD(size.z), "See Model.size_x" },
|
---|
31 | { "bboxSize", 0, PARAM_READONLY | PARAM_NOSTATIC, "Bounding box size", "oXYZ", GETONLY(bboxsize) },
|
---|
32 | { "numcheckpoints", 0, PARAM_DONTSAVE | PARAM_READONLY | PARAM_NOSTATIC, "Number of checkpoints", "d", GETONLY(numcheckpoints) },
|
---|
33 | { "getCheckpoint", 0, PARAM_READONLY | PARAM_USERHIDDEN | PARAM_NOSTATIC, "getCheckpoint", "p oModel(d index)", PROCEDURE(p_getcheckpoint),
|
---|
34 | "Checkpoint Model objects are only valid as long as the parent Model object exists.\n"
|
---|
35 | "See also: Model.newWithCheckpoints()\n\n"
|
---|
36 | "// incorrect usage - calling getCheckpoint() on a temporary object:\n"
|
---|
37 | "var c=Model.newWithCheckpoints(\"XXX\").getCheckpoint(1).genotype.geno;\n\n"
|
---|
38 | "// correct usage - keeping the parent Model reference in 'm':\n"
|
---|
39 | "var m=Model.newWithCheckpoints(\"XXX\");\n"
|
---|
40 | "var c=m.getCheckpoint(1).genotype.geno;\n"
|
---|
41 | },
|
---|
42 | { "shape_type", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Shape type", "d 0 3 ~Unknown~Illegal~Ball-and-stick~Solids", GETONLY(shape_type) },
|
---|
43 | { "solid_model", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Solid shapes model", "oModel", GETONLY(solid_model), "Conversion of this Model to solid shapes. Note! Only available when this Model has shape_type==2 (Ball-and-stick)." },
|
---|
44 |
|
---|
45 | { 0, 0, 0, },
|
---|
46 | };
|
---|
47 | #undef FIELDSTRUCT
|
---|
48 |
|
---|
49 | void ModelObj::get_geno(ExtValue *ret)
|
---|
50 | {
|
---|
51 | Geno *g;
|
---|
52 | if ((!geno.isValid()) && isValid())
|
---|
53 | g = new Geno(getF0Geno());
|
---|
54 | else
|
---|
55 | g = new Geno(geno);
|
---|
56 | ret->setObject(GenoObj::makeDynamicObjectAndDecRef(g));
|
---|
57 | }
|
---|
58 |
|
---|
59 | void ModelObj::p_newfromstring(ExtValue *args, ExtValue *ret)
|
---|
60 | {
|
---|
61 | *ret = makeDynamicObject(new Model(Geno(args[0].getString()), Model::SHAPETYPE_UNKNOWN));
|
---|
62 | }
|
---|
63 |
|
---|
64 | void ModelObj::p_newfromgeno(ExtValue *args, ExtValue *ret)
|
---|
65 | {
|
---|
66 | Geno *g = GenoObj::fromObject(args[0].getObject());
|
---|
67 | if (g)
|
---|
68 | *ret = makeDynamicObject(new Model(*g, Model::SHAPETYPE_UNKNOWN));
|
---|
69 | else
|
---|
70 | ret->setEmpty();
|
---|
71 | }
|
---|
72 |
|
---|
73 | void ModelObj::p_newwithcheckpoints(ExtValue *args, ExtValue *ret)
|
---|
74 | {
|
---|
75 | Model *m = NULL;
|
---|
76 | if (args[0].getType() == TString)
|
---|
77 | m = new Model(Geno(args[0].getString()), Model::SHAPETYPE_UNKNOWN, false, true);
|
---|
78 | else
|
---|
79 | {
|
---|
80 | Geno *g = GenoObj::fromObject(args[0].getObject(), false);
|
---|
81 | if (g)
|
---|
82 | m = new Model(*g, Model::SHAPETYPE_UNKNOWN, false, true);
|
---|
83 | else
|
---|
84 | logPrintf("Model", "newWithCheckpoints", LOG_ERROR, "Geno or string expected, %s found", args[0].typeDescription().c_str());
|
---|
85 | }
|
---|
86 |
|
---|
87 | if (m != NULL)
|
---|
88 | *ret = makeDynamicObject(m);
|
---|
89 | else
|
---|
90 | ret->setEmpty();
|
---|
91 | }
|
---|
92 |
|
---|
93 | Param& ModelObj::getStaticParam()
|
---|
94 | {
|
---|
95 | #ifdef __CODEGUARD__
|
---|
96 | static ModelObj static_modelobj;
|
---|
97 | static Param static_modelparam(modelobj_paramtab, &static_modelobj);
|
---|
98 | #else
|
---|
99 | static Param static_modelparam(modelobj_paramtab);
|
---|
100 | #endif
|
---|
101 | return static_modelparam;
|
---|
102 | }
|
---|
103 |
|
---|
104 | Param& ModelObj::getDynamicParam()
|
---|
105 | {
|
---|
106 | static Param dynamic_modelparam(modelobj_paramtab);
|
---|
107 | return dynamic_modelparam;
|
---|
108 | }
|
---|
109 |
|
---|
110 | ParamInterface* ModelObj::getInterface()
|
---|
111 | {
|
---|
112 | return &getStaticParam();
|
---|
113 | }
|
---|
114 |
|
---|
115 | ExtObject ModelObj::makeStaticObject(Model* m)
|
---|
116 | {
|
---|
117 | return ExtObject(&getStaticParam(), (void*)m);
|
---|
118 | }
|
---|
119 |
|
---|
120 | ExtObject ModelObj::makeDynamicObject(Model* m)
|
---|
121 | {
|
---|
122 | return ExtObject(&getDynamicParam(), (DestrBase*)m);
|
---|
123 | }
|
---|
124 |
|
---|
125 | Model* ModelObj::fromObject(const ExtValue& v, bool warn)
|
---|
126 | {
|
---|
127 | return (Model*)v.getObjectTarget(getStaticParam().getName(), warn);
|
---|
128 | }
|
---|
129 |
|
---|
130 | void ModelObj::p_getpart(PARAMPROCARGS)
|
---|
131 | {
|
---|
132 | int i = args->getInt();
|
---|
133 | if ((i < 0) || (i >= getPartCount()))
|
---|
134 | {
|
---|
135 | ret->setEmpty();
|
---|
136 | return;
|
---|
137 | }
|
---|
138 | ret->setObject(ExtObject(&Part::getStaticParam(), getPart(i)));
|
---|
139 | }
|
---|
140 |
|
---|
141 | void ModelObj::p_getjoint(PARAMPROCARGS)
|
---|
142 | {
|
---|
143 | int i = args->getInt();
|
---|
144 | if ((i < 0) || (i >= getJointCount()))
|
---|
145 | {
|
---|
146 | ret->setEmpty();
|
---|
147 | return;
|
---|
148 | }
|
---|
149 | ret->setObject(ExtObject(&Joint::getStaticParam(), getJoint(i)));
|
---|
150 | }
|
---|
151 |
|
---|
152 | void ModelObj::p_getneuro(PARAMPROCARGS)
|
---|
153 | {
|
---|
154 | int i = args->getInt();
|
---|
155 | if ((i < 0) || (i >= getNeuroCount()))
|
---|
156 | {
|
---|
157 | ret->setEmpty();
|
---|
158 | return;
|
---|
159 | }
|
---|
160 | ret->setObject(ExtObject(&Neuro::getStaticParam(), getNeuro(i)));
|
---|
161 | }
|
---|
162 |
|
---|
163 | void ModelObj::get_bboxsize(ExtValue *ret)
|
---|
164 | {
|
---|
165 | *ret = Pt3D_Ext::makeDynamicObject(new Pt3D_Ext(size));
|
---|
166 | }
|
---|
167 |
|
---|
168 | void ModelObj::p_getcheckpoint(PARAMPROCARGS)
|
---|
169 | {
|
---|
170 | int i = args->getInt();
|
---|
171 | if ((i < 0) || (i >= getCheckpointCount()))
|
---|
172 | {
|
---|
173 | ret->setEmpty();
|
---|
174 | return;
|
---|
175 | }
|
---|
176 | ret->setObject(makeStaticObject(getCheckpoint(i)));
|
---|
177 | }
|
---|
178 |
|
---|
179 | void ModelObj::get_solid_model(ExtValue *ret)
|
---|
180 | {
|
---|
181 | if (getShapeType() != Model::SHAPETYPE_BALL_AND_STICK)
|
---|
182 | ret->setEmpty();
|
---|
183 | Model *m = new Model;
|
---|
184 | m->open();
|
---|
185 | m->buildUsingSolidShapeTypes(*this);
|
---|
186 | m->close();
|
---|
187 | *ret = makeDynamicObject(m);
|
---|
188 | }
|
---|
189 |
|
---|
190 | void ModelObj::get_shape_type(ExtValue *ret)
|
---|
191 | {
|
---|
192 | ret->setInt(getShapeType());
|
---|
193 | }
|
---|
194 |
|
---|
195 | void ModelObj::get_is_valid(ExtValue *ret)
|
---|
196 | {
|
---|
197 | ret->setInt(isValid());
|
---|
198 | }
|
---|