-
Notifications
You must be signed in to change notification settings - Fork 1k
add SPLAT decoder to be able to encode .splat files to .drc files #1097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
patrikant
wants to merge
6
commits into
google:main
Choose a base branch
from
patrikant:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0b3b8f3
add SPLAT decoder to be able to encode .splat files to .drc files
patrikant 5a5858c
add SPLAT decoder to be able to encode .splat files to .drc files
patrikant ccef483
Merge branch 'main' of https://github.com/patrikant/draco
patrikant 0a257cb
Merge branch 'main' into main
patrikant 073c42c
resolve typo
patrikant 0b8d161
check if file extension exists (fix failing test)
patrikant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2025 Patrick Trollmann. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#include "draco/io/splat_decoder.h" | ||
|
||
namespace draco { | ||
SplatDecoder::SplatDecoder() {} | ||
|
||
Status SplatDecoder::ReadSplatFile(const std::string &filename, | ||
PointCloud *out_point_cloud) { | ||
std::ifstream file(filename, std::ios::binary); | ||
if (!file) { | ||
return Status(Status::DRACO_ERROR, "Unable to open input file."); | ||
} | ||
|
||
struct Gaussian { | ||
float position[3]; | ||
float scale[3]; | ||
uint8_t color[4]; | ||
uint8_t rotation[4]; | ||
}; | ||
|
||
std::vector<Gaussian> gaussians; | ||
Gaussian gaussian; | ||
while (file.read(reinterpret_cast<char *>(&gaussian), sizeof(Gaussian))) { | ||
gaussians.push_back(gaussian); | ||
} | ||
const PointIndex::ValueType num_vertices = gaussians.size(); | ||
out_point_cloud->set_num_points(num_vertices); | ||
|
||
GeometryAttribute vapos; | ||
vapos.Init(GeometryAttribute::POSITION, nullptr, 6, DT_FLOAT32, false, | ||
sizeof(float) * 6, 0); | ||
const int att_id_position = | ||
out_point_cloud->AddAttribute(vapos, true, num_vertices); | ||
|
||
GeometryAttribute vacol; | ||
vacol.Init(GeometryAttribute::COLOR, nullptr, 8, DT_UINT8, true, | ||
sizeof(uint8_t) * 8, 0); | ||
const int att_id_color = | ||
out_point_cloud->AddAttribute(vacol, true, num_vertices); | ||
|
||
for (PointIndex::ValueType i = 0; i < num_vertices; ++i) { | ||
const auto &g = gaussians[i]; | ||
std::array<float, 6> valpos; | ||
valpos[0] = g.position[0]; | ||
valpos[1] = g.position[1]; | ||
valpos[2] = g.position[2]; | ||
valpos[3] = g.scale[0]; | ||
valpos[4] = g.scale[1]; | ||
valpos[5] = g.scale[2]; | ||
out_point_cloud->attribute(att_id_position) | ||
->SetAttributeValue(AttributeValueIndex(i), &valpos[0]); | ||
|
||
std::array<uint8_t, 8> valcol; | ||
for (int j = 0; j < 4; j++) { | ||
valcol[j] = g.color[j]; | ||
} | ||
for (int j = 4; j < 8; j++) { | ||
valcol[j] = g.rotation[j-4]; | ||
} | ||
out_point_cloud->attribute(att_id_color) | ||
->SetAttributeValue(AttributeValueIndex(i), &valcol[0]); | ||
} | ||
return OkStatus(); | ||
} | ||
} // namespace draco |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2025 Patrick Trollmann. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#ifndef DRACO_IO_SPLAT_DECODER_H_ | ||
#define DRACO_IO_SPLAT_DECODER_H_ | ||
|
||
#include <fstream> | ||
#include <vector> | ||
|
||
#include "draco/point_cloud/point_cloud.h" | ||
#include "draco/core/status.h" | ||
|
||
namespace draco { | ||
|
||
// Decodes a SPLAT file into draco::PointCloud. | ||
// The current implementation assumes the properties: POSITION, SCALE, COLOR, ROTATION. | ||
// POSITION and SCALE are stored together as GeometryAttribute.POSITION. COLOR and ROTATION | ||
// are stored together as GeometryAttribute.COLOR. Currently, it is not possible to use | ||
// custom GeometryAttribute types or the GENERIC type. This types cannot be decoded in | ||
// the WebGL version of Draco. | ||
class SplatDecoder { | ||
public: | ||
SplatDecoder(); | ||
|
||
// Decodes a splat file stored in the input file. | ||
Status ReadSplatFile(const std::string &filename, | ||
PointCloud *out_point_cloud); | ||
|
||
}; | ||
|
||
} // namespace draco | ||
|
||
#endif // DRACO_IO_SPLAT_DECODER_H_ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any official SPLAT file specification / definition that we could link to here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am using the definition by antimatter15: https://github.com/antimatter15/splat