Skip to content
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

Can I support ply export splat files #332

Open
chaoyang915506 opened this issue Sep 14, 2024 · 4 comments
Open

Can I support ply export splat files #332

chaoyang915506 opened this issue Sep 14, 2024 · 4 comments

Comments

@chaoyang915506
Copy link

I saw downloadFile under ksplatloader. js file to download ksplat file directly. SplatLoader.js I tried to add downloadFile method under KSplatLoader and found that the exported splat could not be used. I want to export a splat file.

@mkkellogg
Copy link
Owner

Currently I don't have any way to export to .splat format in my viewer. What is your source format? You can always use the antimatter15 viewer or SuperSplat to export to .splat.

@chaoyang915506
Copy link
Author

chaoyang915506 commented Sep 14, 2024

https://huggingface.co/spaces/dylanebert/gsplat-editor
Ok, my source data is ply format files, it would be great if I could export ply and splat based on the rendered content just like the site in the link.

@gotoeasy
Copy link

gotoeasy commented Sep 14, 2024

https://huggingface.co/spaces/dylanebert/gsplat-editor
Ok, my source data is ply format files, it would be great if I could export ply and splat based on the rendered content just like the site in the link.

# 3dgs ply to splat
gsbox -i /path/to/input.ply -o /path/to/output.splat

# splat to 3dgs ply
gsbox -i /path/to/input.splat -o /path/to/output.ply

https://github.com/gotoeasy/gsbox

@FanYaning
Copy link

from plyfile import PlyData
import numpy as np
from io import BytesIO
def process_ply_to_splat(ply_file_path, splat_file_path):
    plydata = PlyData.read(ply_file_path)
    vert = plydata["vertex"]
    buffer = BytesIO()
    SH_C0 = 0.28209479177387814
    for v in vert:
        position = np.array([v["x"], v["y"], v["z"]], dtype=np.float32)
        scales = np.exp(
            np.array(
                [v["scale_0"], v["scale_1"], v["scale_2"]],
                dtype=np.float32,
            )
        )
        rot = np.array(
            [v["rot_0"], v["rot_1"], v["rot_2"], v["rot_3"]],
            dtype=np.float32,
        )
        color = np.array(
            [
                0.5 + SH_C0 * v["f_dc_0"],
                0.5 + SH_C0 * v["f_dc_1"],
                0.5 + SH_C0 * v["f_dc_2"],
                1 / (1 + np.exp(-v["opacity"])),
            ]
        )
        buffer.write(position.tobytes())
        buffer.write(scales.tobytes())
        buffer.write((color * 255).clip(0, 255).astype(np.uint8).tobytes())
        buffer.write(
            ((rot / np.linalg.norm(rot)) * 128 + 128)
            .clip(0, 255)
            .astype(np.uint8)
            .tobytes()
        )
        with open(splat_file_path, "wb") as f:
            f.write(buffer.getvalue())
        buffer.close()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants