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

GSplatComponent that allows native integration of splat tech with the Entity #5976

Merged
merged 1 commit into from Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions examples/src/examples/loaders/gsplat-many.mjs
Expand Up @@ -26,7 +26,8 @@ async function example({ canvas, deviceType, assetPath, scriptsPath, glslangPath
pc.RenderComponentSystem,
pc.CameraComponentSystem,
pc.LightComponentSystem,
pc.ScriptComponentSystem
pc.ScriptComponentSystem,
pc.GSplatComponentSystem
];
createOptions.resourceHandlers = [
// @ts-ignore
Expand Down Expand Up @@ -55,8 +56,8 @@ async function example({ canvas, deviceType, assetPath, scriptsPath, glslangPath

const assets = {
gallery: new pc.Asset('gallery', 'container', { url: assetPath + 'models/vr-gallery.glb' }),
guitar: new pc.Asset('splat', 'gsplat', { url: assetPath + 'splats/guitar.ply' }),
biker: new pc.Asset('splat', 'gsplat', { url: assetPath + 'splats/biker.ply' }),
guitar: new pc.Asset('gsplat', 'gsplat', { url: assetPath + 'splats/guitar.ply' }),
biker: new pc.Asset('gsplat', 'gsplat', { url: assetPath + 'splats/biker.ply' }),
orbit: new pc.Asset('script', 'script', { url: scriptsPath + 'camera/orbit-camera.js' })
};

Expand All @@ -80,8 +81,7 @@ async function example({ canvas, deviceType, assetPath, scriptsPath, glslangPath

const createSplatInstance = (name, resource, px, py, pz, scale, vertex, fragment) => {

const splat = resource.instantiateRenderEntity({
cameraEntity: camera,
const splat = resource.instantiate({
debugRender: false,
fragment: fragment,
vertex: vertex
Expand All @@ -95,8 +95,12 @@ async function example({ canvas, deviceType, assetPath, scriptsPath, glslangPath

const guitar = createSplatInstance('guitar', assets.guitar.resource, 0, 0.8, 0, 0.4, files['shader.vert'], files['shader.frag']);
const biker1 = createSplatInstance('biker1', assets.biker.resource, -1.5, 0.05, 0, 0.7);
const biker2 = createSplatInstance('biker2', assets.biker.resource, 1.5, 0.05, 0.8, 0.7);

// clone the biker and add the clone to the scene
const biker2 = biker1.clone();
biker2.setLocalPosition(1.5, 0.05, 0);
biker2.rotate(0, 150, 0);
app.root.addChild(biker2);

// add orbit camera script with a mouse and a touch support
camera.addComponent("script");
Expand All @@ -116,7 +120,7 @@ async function example({ canvas, deviceType, assetPath, scriptsPath, glslangPath
app.on("update", function (dt) {
currentTime += dt;

const material = guitar.render.meshInstances[0].material;
const material = guitar.gsplat.material;
material.setParameter('uTime', currentTime);
});
});
Expand Down
8 changes: 4 additions & 4 deletions examples/src/examples/loaders/gsplat.mjs
Expand Up @@ -26,7 +26,8 @@ async function example({ canvas, deviceType, assetPath, scriptsPath, glslangPath
pc.RenderComponentSystem,
pc.CameraComponentSystem,
pc.LightComponentSystem,
pc.ScriptComponentSystem
pc.ScriptComponentSystem,
pc.GSplatComponentSystem
];
createOptions.resourceHandlers = [
// @ts-ignore
Expand Down Expand Up @@ -54,7 +55,7 @@ async function example({ canvas, deviceType, assetPath, scriptsPath, glslangPath
});

const assets = {
biker: new pc.Asset('splat', 'gsplat', { url: assetPath + 'splats/biker.ply' }),
biker: new pc.Asset('gsplat', 'gsplat', { url: assetPath + 'splats/biker.ply' }),
orbit: new pc.Asset('script', 'script', { url: scriptsPath + 'camera/orbit-camera.js' })
};

Expand All @@ -74,8 +75,7 @@ async function example({ canvas, deviceType, assetPath, scriptsPath, glslangPath

const createSplatInstance = (resource, px, py, pz, scale, vertex, fragment) => {

const splat = resource.instantiateRenderEntity({
cameraEntity: camera,
const splat = resource.instantiate({
debugRender: false,
fragment: fragment,
vertex: vertex
Expand Down
9 changes: 9 additions & 0 deletions scripts/camera/orbit-camera.js
Expand Up @@ -310,6 +310,15 @@ OrbitCamera.prototype._buildAabb = function (entity) {
}
}

var gsplats = entity.findComponents("gsplat");
for (i = 0; i < gsplats.length; i++) {
var gsplat = gsplats[i];
var instance = gsplat.instance;
if (instance) {
meshInstances.push(instance.meshInstance);
}
}

for (i = 0; i < meshInstances.length; i++) {
if (i === 0) {
this._modelsAabb.copy(meshInstances[i].aabb);
Expand Down