File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,21 @@ namespace Box2d {
2020 return jsi::Value::undefined ();
2121 }
2222
23- JSI_EXPORT_FUNCTIONS (JSI_EXPORT_FUNC(JSIBox2dPolygonShape, SetAsBox))
23+ JSI_HOST_FUNCTION (Set) {
24+ auto array = arguments[0 ].asObject (runtime).asArray (runtime);
25+ auto n = static_cast <int32>(array.length (runtime));
26+ b2Vec2 points[n];
27+ for (int32 i = 0 ; i < n; ++i) {
28+ auto point = JSIBox2dVec2::fromValue (runtime, array.getValueAtIndex (runtime, i));
29+ points[i].x = point->x ;
30+ points[i].y = point->y ;
31+ }
32+ getObject ()->Set (points, n);
33+ return jsi::Value::undefined ();
34+ }
35+
36+ JSI_EXPORT_FUNCTIONS (JSI_EXPORT_FUNC(JSIBox2dPolygonShape, SetAsBox),
37+ JSI_EXPORT_FUNC (JSIBox2dPolygonShape, Set))
2438
2539 /* *
2640 * Constructor
Original file line number Diff line number Diff line change @@ -33,6 +33,13 @@ export interface b2PolygonShape extends b2Shape {
3333 * @return Box polygon shape.
3434 **/
3535 SetAsBox ( hx : number , hy : number ) : void ;
36+
37+ /**
38+ * Create a convex hull from the given array of local points. The count must be in the range [3, b2_maxPolygonVertices].
39+ * @param points The array of local points.
40+ * @return Polygon shape.
41+ **/
42+ Set ( points : b2Vec2 [ ] ) : void ;
3643}
3744
3845export interface b2CircleShape extends b2Shape {
You can’t perform that action at this time.
0 commit comments