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

[WIP] Adding color options to entities #992

Closed
wants to merge 3 commits into from
Closed
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
35 changes: 35 additions & 0 deletions src/components/accent-color.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* global AFRAME */

AFRAME.registerComponent('accent-color', {
schema: {
color: {
type: 'color'
},
index: {
type: 'int'
}
},
init: function () {
// Want the color update to apply when the mixin is loaded,
// which may be at a different time than the component
this.el.addEventListener('model-loaded', () => this.update());
},
update: function (oldData) {
// Collect meshes
const meshes = [];
this.el.object3D.traverse((o) => o.material && meshes.push(o));
// Remove the tint on the previous mesh
if (oldData && oldData.index !== this.data.index) {
const oldMesh = meshes.at(oldData.index);
oldMesh && oldMesh.material.color.set(1, 1, 1);
}
// Ignore negative index
if (this.data.index < 0) return;
// Apply tint to selected mesh
const mesh = meshes.at(this.data.index);
if (mesh) {
mesh.material.color.set(this.data.color);
mesh.material.color.multiplyScalar(255);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you multiply by 255?

}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ const createEntity = (mixinId) => {
}
const newEntityObject = {
mixin: mixinId,
components: {}
components: {
'accent-color': {
index: -1
}
}
Copy link
Collaborator

@vincentfretin vincentfretin Dec 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't add the component by default, that's not needed unless you use it. I would create a button in the Sidebar for example "customize color" (for mixins that makes sense) that adds the component to the entity. You can do that with AFRAME.INSPECTOR.execute('componentadd', {entity: entity, component: 'accent-color', value: ''})

};

const selectedElement = AFRAME.INSPECTOR.selectedEntity;
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require('./lib/animation-mixer.js');
require('./lib/aframe-gaussian-splatting-component.min.js');
require('./assets.js');
require('./components/notify.js');
require('./components/accent-color.js');
require('./components/create-from-json');
require('./components/screentock.js');
require('aframe-atlas-uvs-component');
Expand Down
Loading