Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrocortesark committed Oct 9, 2024
1 parent b5b58a1 commit 73999e0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/bindings/bnd_pointcloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,29 @@ BND_DICT BND_PointCloud::ToThreejsJSON() const

}

BND_PointCloud* BND_PointCloud::CreateFromThreejsJSON(BND_DICT json)
{
if (emscripten::val::undefined() == json["data"])
return nullptr;
emscripten::val attributes = json["data"]["attributes"];

std::vector<float> position_array = emscripten::vecFromJSArray<float>(attributes["position"]["array"]);

ON_PointCloud* pc = new ON_PointCloud();

const int vertex_count = position_array.size() / 3;
pc->m_V.SetCapacity(vertex_count);
pc->m_V.SetCount(vertex_count);
memcpy(pc->m_V.Array(), position_array.data(), sizeof(float) * position_array.size());

ON_Xform rotation(1);
rotation.RotationZYX(0.0, 0.0, ON_PI / 2.0);
pc->Transform(rotation);

return new BND_PointCloud(pc, nullptr);
}



#endif

Expand Down Expand Up @@ -936,6 +959,7 @@ void initPointCloudBindings(void*)
.function("getValues", &BND_PointCloud::GetValues)
.function("closestPoint", &BND_PointCloud::ClosestPoint)
.function("toThreejsJSON", &BND_PointCloud::ToThreejsJSON)
.class_function("createFromThreejsJSON", &BND_PointCloud::CreateFromThreejsJSON)
;
}
#endif
1 change: 1 addition & 0 deletions src/bindings/bnd_pointcloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ class BND_PointCloud : public BND_GeometryBase //IEnumerable<PointCloudItem>

#if defined(ON_WASM_COMPILE)
BND_DICT ToThreejsJSON() const;
static BND_PointCloud CreateFromThreejsJSON(BND_DICT json);
#endif
};

0 comments on commit 73999e0

Please sign in to comment.