KHR_gaussian_splatting extension

This commit is contained in:
Ashley Rogers 2025-07-11 10:22:17 -04:00
parent 70bd62a9f4
commit d6e4d5d847
10 changed files with 348 additions and 1 deletions

View File

@ -0,0 +1,42 @@
// This file was generated by generate-classes.
// DO NOT EDIT THIS FILE!
#pragma once
#include <CesiumGltf/Library.h>
#include <CesiumUtility/ExtensibleObject.h>
namespace CesiumGltf {
/**
* @brief glTF extension for rendering Gaussian splats.
*/
struct CESIUMGLTF_API ExtensionKhrGaussianSplatting final
: public CesiumUtility::ExtensibleObject {
/**
* @brief The original name of this type.
*/
static constexpr const char* TypeName = "ExtensionKhrGaussianSplatting";
/** @brief The official name of the extension. This should be the same as its
* key in the `extensions` object. */
static constexpr const char* ExtensionName = "KHR_gaussian_splatting";
/**
* @brief Scale used when dequantizing position attribute values
*/
double quantizedPositionScale = 1;
/**
* @brief Calculates the size in bytes of this object, including the contents
* of all collections, pointers, and strings. This will NOT include the size
* of any extensions attached to the object. Calling this method may be slow
* as it requires traversing the object's entire structure.
*/
int64_t getSizeBytes() const {
int64_t accum = 0;
accum += int64_t(sizeof(ExtensionKhrGaussianSplatting));
accum += CesiumUtility::ExtensibleObject::getSizeBytes() -
int64_t(sizeof(CesiumUtility::ExtensibleObject));
return accum;
}
};
} // namespace CesiumGltf

View File

@ -0,0 +1,77 @@
// This file was generated by generate-classes.
// DO NOT EDIT THIS FILE!
#pragma once
#include <CesiumGltf/ExtensionKhrGaussianSplatting.h>
#include <CesiumGltfReader/Library.h>
#include <CesiumJsonReader/JsonReader.h>
#include <CesiumJsonReader/JsonReaderOptions.h>
#include <rapidjson/fwd.h>
#include <span>
#include <vector>
namespace CesiumGltf {
struct ExtensionKhrGaussianSplatting;
} // namespace CesiumGltf
namespace CesiumGltfReader {
/**
* @brief Reads \ref CesiumGltf::ExtensionKhrGaussianSplatting
* "ExtensionKhrGaussianSplatting" instances from JSON.
*/
class CESIUMGLTFREADER_API ExtensionKhrGaussianSplattingReader {
public:
/**
* @brief Constructs a new instance.
*/
ExtensionKhrGaussianSplattingReader();
/**
* @brief Gets the options controlling how the JSON is read.
*/
CesiumJsonReader::JsonReaderOptions& getOptions();
/**
* @brief Gets the options controlling how the JSON is read.
*/
const CesiumJsonReader::JsonReaderOptions& getOptions() const;
/**
* @brief Reads an instance of ExtensionKhrGaussianSplatting from a byte
* buffer.
*
* @param data The buffer from which to read the instance.
* @return The result of reading the instance.
*/
CesiumJsonReader::ReadJsonResult<CesiumGltf::ExtensionKhrGaussianSplatting>
readFromJson(const std::span<const std::byte>& data) const;
/**
* @brief Reads an instance of ExtensionKhrGaussianSplatting from a
* rapidJson::Value.
*
* @param value The value from which to read the instance.
* @return The result of reading the instance.
*/
CesiumJsonReader::ReadJsonResult<CesiumGltf::ExtensionKhrGaussianSplatting>
readFromJson(const rapidjson::Value& value) const;
/**
* @brief Reads an array of instances of ExtensionKhrGaussianSplatting from a
* rapidJson::Value.
*
* @param value The value from which to read the array of instances.
* @return The result of reading the array of instances.
*/
CesiumJsonReader::ReadJsonResult<
std::vector<CesiumGltf::ExtensionKhrGaussianSplatting>>
readArrayFromJson(const rapidjson::Value& value) const;
private:
CesiumJsonReader::JsonReaderOptions _options;
};
} // namespace CesiumGltfReader

View File

@ -0,0 +1,47 @@
// This file was generated by generate-classes.
// DO NOT EDIT THIS FILE!
#pragma once
#include <CesiumGltf/ExtensionKhrGaussianSplatting.h>
#include <CesiumJsonReader/DoubleJsonHandler.h>
#include <CesiumJsonReader/ExtensibleObjectJsonHandler.h>
namespace CesiumJsonReader {
class JsonReaderOptions;
} // namespace CesiumJsonReader
namespace CesiumGltfReader {
class ExtensionKhrGaussianSplattingJsonHandler
: public CesiumJsonReader::ExtensibleObjectJsonHandler,
public CesiumJsonReader::IExtensionJsonHandler {
public:
using ValueType = CesiumGltf::ExtensionKhrGaussianSplatting;
static constexpr const char* ExtensionName = "KHR_gaussian_splatting";
explicit ExtensionKhrGaussianSplattingJsonHandler(
const CesiumJsonReader::JsonReaderOptions& options) noexcept;
void reset(
IJsonHandler* pParentHandler,
CesiumGltf::ExtensionKhrGaussianSplatting* pObject);
IJsonHandler* readObjectKey(const std::string_view& str) override;
void reset(
IJsonHandler* pParentHandler,
CesiumUtility::ExtensibleObject& o,
const std::string_view& extensionName) override;
IJsonHandler& getHandler() override { return *this; }
protected:
IJsonHandler* readObjectKeyExtensionKhrGaussianSplatting(
const std::string& objectType,
const std::string_view& str,
CesiumGltf::ExtensionKhrGaussianSplatting& o);
private:
CesiumGltf::ExtensionKhrGaussianSplatting* _pObject = nullptr;
CesiumJsonReader::DoubleJsonHandler _quantizedPositionScale;
};
} // namespace CesiumGltfReader

View File

@ -2974,6 +2974,126 @@ ExtensionExtPrimitiveVoxelsReader::readArrayFromJson(
return CesiumJsonReader::JsonReader::readJson(value, handler);
}
} // namespace CesiumGltfReader
// This file was generated by generate-classes.
// DO NOT EDIT THIS FILE!
// NOLINTBEGIN(readability-duplicate-include)
#include "ExtensionKhrGaussianSplattingJsonHandler.h"
#include "registerReaderExtensions.h"
#include <CesiumGltf/ExtensionKhrGaussianSplatting.h>
#include <CesiumGltfReader/ExtensionKhrGaussianSplattingReader.h>
#include <CesiumJsonReader/ArrayJsonHandler.h>
#include <CesiumJsonReader/ExtensibleObjectJsonHandler.h>
#include <CesiumJsonReader/IJsonHandler.h>
#include <CesiumJsonReader/JsonReader.h>
#include <CesiumUtility/Assert.h>
#include <CesiumUtility/ExtensibleObject.h>
#include <rapidjson/document.h>
#include <any>
#include <cstddef>
#include <span>
#include <string>
#include <string_view>
#include <vector>
// NOLINTEND(readability-duplicate-include)
namespace CesiumGltfReader {
ExtensionKhrGaussianSplattingJsonHandler::
ExtensionKhrGaussianSplattingJsonHandler(
const CesiumJsonReader::JsonReaderOptions& options) noexcept
: CesiumJsonReader::ExtensibleObjectJsonHandler(options),
_quantizedPositionScale() {}
void ExtensionKhrGaussianSplattingJsonHandler::reset(
CesiumJsonReader::IJsonHandler* pParentHandler,
CesiumGltf::ExtensionKhrGaussianSplatting* pObject) {
CesiumJsonReader::ExtensibleObjectJsonHandler::reset(pParentHandler, pObject);
this->_pObject = pObject;
}
CesiumJsonReader::IJsonHandler*
ExtensionKhrGaussianSplattingJsonHandler::readObjectKey(
const std::string_view& str) {
CESIUM_ASSERT(this->_pObject);
return this->readObjectKeyExtensionKhrGaussianSplatting(
CesiumGltf::ExtensionKhrGaussianSplatting::TypeName,
str,
*this->_pObject);
}
void ExtensionKhrGaussianSplattingJsonHandler::reset(
CesiumJsonReader::IJsonHandler* pParentHandler,
CesiumUtility::ExtensibleObject& o,
const std::string_view& extensionName) {
std::any& value =
o.extensions
.emplace(extensionName, CesiumGltf::ExtensionKhrGaussianSplatting())
.first->second;
this->reset(
pParentHandler,
&std::any_cast<CesiumGltf::ExtensionKhrGaussianSplatting&>(value));
}
CesiumJsonReader::IJsonHandler* ExtensionKhrGaussianSplattingJsonHandler::
readObjectKeyExtensionKhrGaussianSplatting(
const std::string& objectType,
const std::string_view& str,
CesiumGltf::ExtensionKhrGaussianSplatting& o) {
using namespace std::string_literals;
if ("quantizedPositionScale"s == str) {
return property(
"quantizedPositionScale",
this->_quantizedPositionScale,
o.quantizedPositionScale);
}
return this->readObjectKeyExtensibleObject(objectType, str, *this->_pObject);
}
ExtensionKhrGaussianSplattingReader::ExtensionKhrGaussianSplattingReader() {
registerReaderExtensions(this->_options);
}
CesiumJsonReader::JsonReaderOptions&
ExtensionKhrGaussianSplattingReader::getOptions() {
return this->_options;
}
const CesiumJsonReader::JsonReaderOptions&
ExtensionKhrGaussianSplattingReader::getOptions() const {
return this->_options;
}
CesiumJsonReader::ReadJsonResult<CesiumGltf::ExtensionKhrGaussianSplatting>
ExtensionKhrGaussianSplattingReader::readFromJson(
const std::span<const std::byte>& data) const {
ExtensionKhrGaussianSplattingJsonHandler handler(this->_options);
return CesiumJsonReader::JsonReader::readJson(data, handler);
}
CesiumJsonReader::ReadJsonResult<CesiumGltf::ExtensionKhrGaussianSplatting>
ExtensionKhrGaussianSplattingReader::readFromJson(
const rapidjson::Value& value) const {
ExtensionKhrGaussianSplattingJsonHandler handler(this->_options);
return CesiumJsonReader::JsonReader::readJson(value, handler);
}
CesiumJsonReader::ReadJsonResult<
std::vector<CesiumGltf::ExtensionKhrGaussianSplatting>>
ExtensionKhrGaussianSplattingReader::readArrayFromJson(
const rapidjson::Value& value) const {
CesiumJsonReader::ArrayJsonHandler<
CesiumGltf::ExtensionKhrGaussianSplatting,
ExtensionKhrGaussianSplattingJsonHandler>
handler(this->_options);
return CesiumJsonReader::JsonReader::readJson(value, handler);
}
} // namespace CesiumGltfReader
// This file was generated by generate-classes.
// DO NOT EDIT THIS FILE!

View File

@ -16,6 +16,7 @@
#include "ExtensionExtPrimitiveVoxelsJsonHandler.h"
#include "ExtensionExtStructuralMetadataJsonHandler.h"
#include "ExtensionKhrDracoMeshCompressionJsonHandler.h"
#include "ExtensionKhrGaussianSplattingJsonHandler.h"
#include "ExtensionKhrImplicitShapesJsonHandler.h"
#include "ExtensionKhrMaterialsUnlitJsonHandler.h"
#include "ExtensionKhrTextureBasisuJsonHandler.h"
@ -81,6 +82,9 @@ void registerReaderExtensions(CesiumJsonReader::JsonReaderOptions& options) {
options.registerExtension<
CesiumGltf::MeshPrimitive,
ExtensionExtPrimitiveVoxelsJsonHandler>();
options.registerExtension<
CesiumGltf::MeshPrimitive,
ExtensionKhrGaussianSplattingJsonHandler>();
options.registerExtension<
CesiumGltf::Node,
ExtensionExtInstanceFeaturesJsonHandler>();

View File

@ -38,6 +38,7 @@
#include <CesiumGltf/ExtensionExtPrimitiveVoxels.h>
#include <CesiumGltf/ExtensionExtStructuralMetadata.h>
#include <CesiumGltf/ExtensionKhrDracoMeshCompression.h>
#include <CesiumGltf/ExtensionKhrGaussianSplatting.h>
#include <CesiumGltf/ExtensionKhrImplicitShapes.h>
#include <CesiumGltf/ExtensionKhrMaterialsUnlit.h>
#include <CesiumGltf/ExtensionKhrTextureBasisu.h>
@ -218,6 +219,11 @@ void writeJson(
CesiumJsonWriter::JsonWriter& jsonWriter,
const CesiumJsonWriter::ExtensionWriterContext& context);
void writeJson(
const CesiumGltf::ExtensionKhrGaussianSplatting& obj,
CesiumJsonWriter::JsonWriter& jsonWriter,
const CesiumJsonWriter::ExtensionWriterContext& context);
void writeJson(
const CesiumGltf::Padding& obj,
CesiumJsonWriter::JsonWriter& jsonWriter,
@ -1174,6 +1180,22 @@ void writeJson(
jsonWriter.EndObject();
}
void writeJson(
const CesiumGltf::ExtensionKhrGaussianSplatting& obj,
CesiumJsonWriter::JsonWriter& jsonWriter,
const CesiumJsonWriter::ExtensionWriterContext& context) {
jsonWriter.StartObject();
if (obj.quantizedPositionScale != 1) {
jsonWriter.Key("quantizedPositionScale");
writeJson(obj.quantizedPositionScale, jsonWriter, context);
}
writeExtensibleObject(obj, jsonWriter, context);
jsonWriter.EndObject();
}
void writeJson(
const CesiumGltf::Padding& obj,
CesiumJsonWriter::JsonWriter& jsonWriter,
@ -2892,6 +2914,13 @@ void ExtensionExtPrimitiveVoxelsJsonWriter::write(
writeJson(obj, jsonWriter, context);
}
void ExtensionKhrGaussianSplattingJsonWriter::write(
const CesiumGltf::ExtensionKhrGaussianSplatting& obj,
CesiumJsonWriter::JsonWriter& jsonWriter,
const CesiumJsonWriter::ExtensionWriterContext& context) {
writeJson(obj, jsonWriter, context);
}
void PaddingJsonWriter::write(
const CesiumGltf::Padding& obj,
CesiumJsonWriter::JsonWriter& jsonWriter,

View File

@ -34,6 +34,7 @@ struct ExtensionKhrImplicitShapes;
struct ExtensionExtImplicitEllipsoidRegion;
struct ExtensionExtImplicitCylinderRegion;
struct ExtensionExtPrimitiveVoxels;
struct ExtensionKhrGaussianSplatting;
struct Padding;
struct Shape;
struct Cylinder;
@ -402,6 +403,19 @@ struct ExtensionExtPrimitiveVoxelsJsonWriter {
const CesiumJsonWriter::ExtensionWriterContext& context);
};
struct ExtensionKhrGaussianSplattingJsonWriter {
using ValueType = CesiumGltf::ExtensionKhrGaussianSplatting;
/** @brief The official name of the extension. This should be the same as its
* key in the `extensions` object. */
static constexpr const char* ExtensionName = "KHR_gaussian_splatting";
static void write(
const CesiumGltf::ExtensionKhrGaussianSplatting& obj,
CesiumJsonWriter::JsonWriter& jsonWriter,
const CesiumJsonWriter::ExtensionWriterContext& context);
};
struct PaddingJsonWriter {
using ValueType = CesiumGltf::Padding;

View File

@ -34,6 +34,7 @@
#include <CesiumGltf/ExtensionExtPrimitiveVoxels.h>
#include <CesiumGltf/ExtensionExtStructuralMetadata.h>
#include <CesiumGltf/ExtensionKhrDracoMeshCompression.h>
#include <CesiumGltf/ExtensionKhrGaussianSplatting.h>
#include <CesiumGltf/ExtensionKhrImplicitShapes.h>
#include <CesiumGltf/ExtensionKhrMaterialsUnlit.h>
#include <CesiumGltf/ExtensionKhrTextureBasisu.h>
@ -86,6 +87,9 @@ void registerWriterExtensions(
context.registerExtension<
CesiumGltf::MeshPrimitive,
ExtensionExtPrimitiveVoxelsJsonWriter>();
context.registerExtension<
CesiumGltf::MeshPrimitive,
ExtensionKhrGaussianSplattingJsonWriter>();
context.registerExtension<
CesiumGltf::Node,
ExtensionExtInstanceFeaturesJsonWriter>();

View File

@ -163,6 +163,9 @@
},
"EXT_primitive_voxels glTF Mesh Primitive extension": {
"overrideName": "ExtensionExtPrimitiveVoxels"
},
"KHR_gaussian_splatting glTF primitive extension": {
"overrideName": "ExtensionKhrGaussianSplatting"
}
},
"extensions": [
@ -287,6 +290,13 @@
{
"extensionName": "EXT_primitive_voxels",
"schema": "Vendor/EXT_primitive_voxels/schema/mesh.primitive.EXT_primitive_voxels.schema.json"
},
{
"extensionName": "KHR_gaussian_splatting",
"schema": "Khronos/KHR_gaussian_splatting/schema/primitive.KHR_gaussian_splatting.schema.json",
"attachTo": [
"mesh.primitive"
]
}
]
}

View File

@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"generate-3d-tiles": "node index.js --schemas https://raw.githubusercontent.com/CesiumGS/3d-tiles/cesium-native/specification/schema/tileset.schema.json https://raw.githubusercontent.com/CesiumGS/3d-tiles/cesium-native/specification/schema/common/rootProperty.schema.json https://raw.githubusercontent.com/CesiumGS/3d-tiles/cesium-native/specification/schema/PropertyTable/propertyTable.schema.json https://raw.githubusercontent.com/CesiumGS/3d-tiles/cesium-native/specification/schema/Subtree/subtree.schema.json https://raw.githubusercontent.com/CesiumGS/3d-tiles/cesium-native/specification/schema/Schema/schema.schema.json https://raw.githubusercontent.com/CesiumGS/3d-tiles/cesium-native/specification/schema/Statistics/statistics.schema.json --output ../../Cesium3DTiles --readerOutput ../../Cesium3DTilesReader --writerOutput ../../Cesium3DTilesWriter --extensions https://raw.githubusercontent.com/CesiumGS/3d-tiles/cesium-native/extensions/ --namespace Cesium3DTiles --readerNamespace Cesium3DTilesReader --writerNamespace Cesium3DTilesWriter --config 3dTiles.json",
"generate-gltf": "node index.js --schemas https://raw.githubusercontent.com/CesiumGS/glTF/cesium-native/specification/2.0/schema/glTF.schema.json --output ../../CesiumGltf --readerOutput ../../CesiumGltfReader --writerOutput ../../CesiumGltfWriter --extensions https://raw.githubusercontent.com/CesiumGS/glTF/cesium-native/extensions/2.0/ --namespace CesiumGltf --readerNamespace CesiumGltfReader --writerNamespace CesiumGltfWriter --config glTF.json",
"generate-gltf": "node index.js --schemas https://raw.githubusercontent.com/CesiumGS/glTF/cesium-native/specification/2.0/schema/glTF.schema.json --output ../../CesiumGltf --readerOutput ../../CesiumGltfReader --writerOutput ../../CesiumGltfWriter --extensions https://raw.githubusercontent.com/CesiumGS/glTF/cesium-native/extensions/2.0/ https://raw.githubusercontent.com/CesiumGS/glTF/spz-extension/extensions/2.0/ --namespace CesiumGltf --readerNamespace CesiumGltfReader --writerNamespace CesiumGltfWriter --config glTF.json",
"generate-quantized-mesh-terrain": "node index.js --schemas ../../CesiumQuantizedMeshTerrain/schema/layer.schema.json --output ../../CesiumQuantizedMeshTerrain --readerOutput ../../CesiumQuantizedMeshTerrain --writerOutput ../../CesiumQuantizedMeshTerrain --extensions ../../CesiumQuantizedMeshTerrain/schema/extensions --namespace CesiumQuantizedMeshTerrain --readerNamespace CesiumQuantizedMeshTerrain --writerNamespace CesiumQuantizedMeshTerrain --config QuantizedMeshTerrain.json"
},
"author": "CesiumGS, Inc. and Contributors",