]>
Dogcows Code - chaz/yoink/blob - src/moof/mesh_bindings.cc
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
20 static int mesh_new(script
& script
)
22 script::slot name
= script
[2].require_string("mesh name");
27 mesh_handle mesh
= resource::load(str
, "ac");
28 if (!mesh
) name
.raise("unable to load mesh from file");
34 static int mesh_draw(script
& script
)
37 script
[1].require_object
<mesh_handle
>("mesh").get(mesh
);
40 if (script
[2].get(alpha
)) (*mesh
)->draw(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
))
77 if (script
[3].get(recurse
)) (*object
)->draw(alpha
, recurse
);
78 else (*object
)->draw(alpha
);
82 if (script
[2].get(recurse
)) (*object
)->draw(SCALAR(0.0), recurse
);
83 else (*object
)->draw();
89 static int object_index(script
& script
)
91 mesh::object_ptr
* object
;
92 script
[1].require_object
<mesh::object_ptr
>("mesh object").get(object
);
94 if (script
[2].is_number())
99 script
.push((*object
)->kids
[index
]);
101 else if (script
[2].is_string())
105 script
.push((*object
)->kids_byname
[name
]);
109 script
[2].raise_type_error("index or name");
115 void mesh::import(script
& script
, const std::string
& nspace
)
117 script
.check_stack(8);
119 script::slot parent
= script
.push_table(nspace
);
120 script::slot meta
= script
.push_class
<mesh_handle
>(mesh_new
);
122 meta
.set_field("draw", mesh_draw
);
123 meta
.set_field("object", mesh_index
);
125 script::slot object_meta
= script
.push_class
<mesh::object_ptr
>(object_new
);
126 object_meta
.set_field("draw", object_draw
);
127 object_meta
.set_field("kid", object_index
);
128 meta
.set_field("__object");
130 parent
.set_field("mesh");
This page took 0.046006 seconds and 4 git commands to generate.