-
Notifications
You must be signed in to change notification settings - Fork 35
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
} | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,7 +145,11 @@ const createEntity = (mixinId) => { | |
} | ||
const newEntityObject = { | ||
mixin: mixinId, | ||
components: {} | ||
components: { | ||
'accent-color': { | ||
index: -1 | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
}; | ||
|
||
const selectedElement = AFRAME.INSPECTOR.selectedEntity; | ||
|
There was a problem hiding this comment.
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?