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

Modified the gsplat examples to create splat instances a more standard way #7053

Merged
merged 2 commits into from
Oct 22, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions examples/src/examples/loaders/gsplat-many.example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,33 @@ assetListLoader.load(() => {
});
camera.setLocalPosition(-3, 1, 2);

const createSplatInstance = (name, resource, px, py, pz, scale, vertex, fragment) => {
const splat = resource.instantiate({
// instantiate guitar with a custom shader
const guitar = assets.guitar.resource.instantiate({
fragment: files['shader.frag'],
vertex: files['shader.vert']
});
guitar.name = 'guitar';
guitar.setLocalPosition(0, 0.8, 0);
guitar.setLocalScale(0.4, 0.4, 0.4);
app.root.addChild(guitar);

// helper function to create a splat instance
const createSplatInstance = (name, asset, px, py, pz, scale, vertex, fragment) => {
const entity = new pc.Entity(name);
entity.addComponent('gsplat', {
asset: asset,
fragment: fragment,
vertex: vertex
mvaligursky marked this conversation as resolved.
Show resolved Hide resolved
});
splat.name = name;
splat.setLocalPosition(px, py, pz);
splat.setLocalScale(scale, scale, scale);
app.root.addChild(splat);
return splat;
entity.setLocalPosition(px, py, pz);
entity.setLocalEulerAngles(180, 90, 0);
entity.setLocalScale(scale, scale, scale);
app.root.addChild(entity);

return entity;
};

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 biker1 = createSplatInstance('biker1', assets.biker, -1.5, 0.05, 0, 0.7);

// clone the biker and add the clone to the scene
const biker2 = biker1.clone();
Expand Down
21 changes: 9 additions & 12 deletions examples/src/examples/loaders/gsplat.example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,15 @@ assetListLoader.load(() => {
});
camera.setLocalPosition(2, 1, 1);

const createSplatInstance = (resource, px, py, pz, scale, vertex, fragment) => {
const splat = resource.instantiate({
fragment: fragment,
vertex: vertex
});
splat.setLocalPosition(px, py, pz);
splat.setLocalScale(scale, scale, scale);
app.root.addChild(splat);
return splat;
};

const biker = createSplatInstance(assets.biker.resource, -1.5, 0.05, 0, 0.7);
// create a splat entity and place it in the world
const biker = new pc.Entity();
biker.addComponent('gsplat', {
asset: assets.biker
});
biker.setLocalPosition(-1.5, 0.05, 0);
biker.setLocalEulerAngles(180, 90, 0);
biker.setLocalScale(0.7, 0.7, 0.7);
app.root.addChild(biker);

// add orbit camera script with a mouse and a touch support
camera.addComponent('script');
Expand Down