]>
Dogcows Code - chaz/yoink/blob - src/moof/mesh_bindings.cc
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
8 *****************************************************************************/
18 static int mesh_new(script
& script
)
20 script::slot name
= script
[2].require_string("mesh name");
25 mesh_handle mesh
= resource::load(str
, "ac");
26 if (!mesh
) name
.raise("unable to load mesh from file");
32 static int mesh_draw(script
& script
)
35 script
[1].require_object
<mesh_handle
>("mesh").get(mesh
);
38 if (script
[2].get(alpha
))
46 static int mesh_index(script
& script
)
49 script
[1].require_object
<mesh_handle
>("mesh").get(mesh
);
52 script
[2].require_number("index").get(index
);
55 script
.push((**mesh
)[index
]);
56 script::slot e
= script
[-1].push_environment();
57 e
.set_field("mesh", *mesh
);
63 static int object_new(script
& script
)
65 return script
.raise("cannot construct a mesh object without a mesh");
68 static int object_draw(script
& script
)
70 mesh::object_ptr
* object
;
71 script
[1].require_object
<mesh::object_ptr
>("mesh object").get(object
);
75 if (script
[2].get(alpha
)) {
76 if (script
[3].get(recurse
))
77 (*object
)->draw(alpha
, recurse
);
79 (*object
)->draw(alpha
);
82 if (script
[2].get(recurse
))
83 (*object
)->draw(SCALAR(0.0), recurse
);
91 static int object_index(script
& script
)
93 mesh::object_ptr
* object
;
94 script
[1].require_object
<mesh::object_ptr
>("mesh object").get(object
);
96 if (script
[2].is_number()) {
100 script
.push((*object
)->kids
[index
]);
102 else if (script
[2].is_string()) {
105 script
.push((*object
)->kids_byname
[name
]);
108 script
[2].raise_type_error("index or name");
114 void mesh::import(script
& script
, const std::string
& nspace
)
116 script
.check_stack(8);
118 script::slot parent
= script
.push_table(nspace
);
119 script::slot meta
= script
.push_class
<mesh_handle
>(mesh_new
);
121 meta
.set_field("draw", mesh_draw
);
122 meta
.set_field("object", mesh_index
);
124 script::slot object_meta
= script
.push_class
<mesh::object_ptr
>(object_new
);
125 object_meta
.set_field("draw", object_draw
);
126 object_meta
.set_field("kid", object_index
);
127 meta
.set_field("__object");
129 parent
.set_field("mesh");
This page took 0.043045 seconds and 5 git commands to generate.