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, 16, "Model", },
|
---|
10 | { "se", 0, PARAM_NOSTATIC, "startenergy", "f", FIELD(startenergy), },
|
---|
11 | { "Vstyle", 0, PARAM_NOSTATIC, "vis_style", "s", FIELD(vis_style), },
|
---|
12 |
|
---|
13 | { "geno", 0, PARAM_NOSTATIC | PARAM_READONLY, "geno", "o Geno", GETONLY(geno), },
|
---|
14 | { "newFromString", 0, 0, "create new object", "p oModel(s genotype)", PROCEDURE(p_newfromstring), },
|
---|
15 | { "newFromGeno", 0, 0, "create new object", "p oModel(oGeno)", PROCEDURE(p_newfromgeno), },
|
---|
16 |
|
---|
17 | { "numparts", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "number of parts", "d", GETONLY(numparts), },
|
---|
18 | { "numjoints", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "number of joints", "d", GETONLY(numjoints), },
|
---|
19 | { "numneurons", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "number of neurons", "d", GETONLY(numneurons), },
|
---|
20 | { "numconnections", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "number of neuron connections", "d", GETONLY(numconnections), },
|
---|
21 |
|
---|
22 | { "getPart", 0, PARAM_USERHIDDEN | PARAM_NOSTATIC, "getPart (static model information)", "p oPart(d index)", PROCEDURE(p_getpart), },
|
---|
23 | { "getJoint", 0, PARAM_USERHIDDEN | PARAM_NOSTATIC, "getJoint (static model information)", "p oJoint(d index)", PROCEDURE(p_getjoint), },
|
---|
24 | { "getNeuroDef", 0, PARAM_USERHIDDEN | PARAM_NOSTATIC, "getNeuroDef", "p oNeuroDef(d index)", PROCEDURE(p_getneuro), },
|
---|
25 |
|
---|
26 | { "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" },
|
---|
27 | { "size_y", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, "bounding box y size", "f", FIELD(size.y), "See Model.size_x" },
|
---|
28 | { "size_z", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, "bounding box z size", "f", FIELD(size.z), "See Model.size_x" },
|
---|
29 | { "bboxSize", 0, PARAM_READONLY | PARAM_NOSTATIC, "Bounding box size", "oXYZ", GETONLY(bboxsize) },
|
---|
30 |
|
---|
31 | { 0, 0, 0, },
|
---|
32 | };
|
---|
33 | #undef FIELDSTRUCT
|
---|
34 |
|
---|
35 | void ModelObj::get_geno(ExtValue *ret)
|
---|
36 | {
|
---|
37 | Geno *g;
|
---|
38 | if ((!geno.isValid()) && isValid())
|
---|
39 | g = new Geno(getF0Geno());
|
---|
40 | else
|
---|
41 | g = new Geno(geno);
|
---|
42 | ret->setObject(GenoObj::makeDynamicObjectAndDecRef(g));
|
---|
43 | }
|
---|
44 |
|
---|
45 | void ModelObj::p_newfromstring(ExtValue *args, ExtValue *ret)
|
---|
46 | {
|
---|
47 | *ret = makeDynamicObject(new Model(Geno(args[0].getString())));
|
---|
48 | }
|
---|
49 |
|
---|
50 | void ModelObj::p_newfromgeno(ExtValue *args, ExtValue *ret)
|
---|
51 | {
|
---|
52 | Geno *g = GenoObj::fromObject(args[0].getObject());
|
---|
53 | if (g)
|
---|
54 | *ret = makeDynamicObject(new Model(*g));
|
---|
55 | else
|
---|
56 | ret->setEmpty();
|
---|
57 | }
|
---|
58 |
|
---|
59 | Param& ModelObj::getStaticParam()
|
---|
60 | {
|
---|
61 | #ifdef __CODEGUARD__
|
---|
62 | static ModelObj static_modelobj;
|
---|
63 | static Param static_modelparam(modelobj_paramtab,&static_modelobj);
|
---|
64 | #else
|
---|
65 | static Param static_modelparam(modelobj_paramtab);
|
---|
66 | #endif
|
---|
67 | return static_modelparam;
|
---|
68 | }
|
---|
69 |
|
---|
70 | Param& ModelObj::getDynamicParam()
|
---|
71 | {
|
---|
72 | static Param dynamic_modelparam(modelobj_paramtab);
|
---|
73 | return dynamic_modelparam;
|
---|
74 | }
|
---|
75 |
|
---|
76 | ParamInterface* ModelObj::getInterface()
|
---|
77 | {
|
---|
78 | return &getStaticParam();
|
---|
79 | }
|
---|
80 |
|
---|
81 | ExtObject ModelObj::makeStaticObject(Model* m)
|
---|
82 | {
|
---|
83 | return ExtObject(&getStaticParam(), (void*)m);
|
---|
84 | }
|
---|
85 |
|
---|
86 | ExtObject ModelObj::makeDynamicObject(Model* m)
|
---|
87 | {
|
---|
88 | return ExtObject(&getDynamicParam(), (DestrBase*)m);
|
---|
89 | }
|
---|
90 |
|
---|
91 | Model* ModelObj::fromObject(const ExtValue& v, bool warn)
|
---|
92 | {
|
---|
93 | return (Model*)v.getObjectTarget(getStaticParam().getName(), warn);
|
---|
94 | }
|
---|
95 |
|
---|
96 | void ModelObj::p_getpart(PARAMPROCARGS)
|
---|
97 | {
|
---|
98 | int i = args->getInt();
|
---|
99 | if ((i < 0) || (i >= getPartCount()))
|
---|
100 | {
|
---|
101 | ret->setEmpty();
|
---|
102 | return;
|
---|
103 | }
|
---|
104 | ret->setObject(ExtObject(&Part::getStaticParam(), getPart(i)));
|
---|
105 | }
|
---|
106 |
|
---|
107 | void ModelObj::p_getjoint(PARAMPROCARGS)
|
---|
108 | {
|
---|
109 | int i = args->getInt();
|
---|
110 | if ((i < 0) || (i >= getJointCount()))
|
---|
111 | {
|
---|
112 | ret->setEmpty();
|
---|
113 | return;
|
---|
114 | }
|
---|
115 | ret->setObject(ExtObject(&Joint::getStaticParam(), getJoint(i)));
|
---|
116 | }
|
---|
117 |
|
---|
118 | void ModelObj::p_getneuro(PARAMPROCARGS)
|
---|
119 | {
|
---|
120 | int i = args->getInt();
|
---|
121 | if ((i < 0) || (i >= getNeuroCount()))
|
---|
122 | {
|
---|
123 | ret->setEmpty();
|
---|
124 | return;
|
---|
125 | }
|
---|
126 | ret->setObject(ExtObject(&Neuro::getStaticParam(), getNeuro(i)));
|
---|
127 | }
|
---|
128 |
|
---|
129 | void ModelObj::get_bboxsize(ExtValue *ret)
|
---|
130 | {
|
---|
131 | *ret = Pt3D_Ext::makeDynamicObject(new Pt3D_Ext(size));
|
---|
132 | }
|
---|