Skip to content

Commit

Permalink
Added grid color and size to controls
Browse files Browse the repository at this point in the history
  • Loading branch information
kpal81xd committed Oct 31, 2024
1 parent 3493c6a commit fe77d48
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/src/examples/gizmos/transform-rotate.example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ data.set('camera', {

// attach grid
app.root.addComponent('script');
const grid = app.root.script.create(Grid);
const grid = /** @type {Grid} */ (app.root.script.create(Grid));
grid.halfExtents = new pc.Vec2(2, 2);
grid.attach(camera.camera);

Expand Down
2 changes: 1 addition & 1 deletion examples/src/examples/gizmos/transform-scale.example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ data.set('camera', {

// attach grid
app.root.addComponent('script');
const grid = app.root.script.create(Grid);
const grid = /** @type {Grid} */ (app.root.script.create(Grid));
grid.halfExtents = new pc.Vec2(2, 2);
grid.attach(camera.camera);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ data.set('camera', {

// attach grid
app.root.addComponent('script');
const grid = app.root.script.create(Grid);
const grid = /** @type {Grid} */ (app.root.script.create(Grid));
grid.halfExtents = new pc.Vec2(2, 2);
grid.attach(camera.camera);

Expand Down
33 changes: 32 additions & 1 deletion examples/src/examples/misc/editor.controls.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as pc from 'playcanvas';
* @returns {JSX.Element} The returned JSX Element.
*/
export function controls({ observer, ReactPCUI, React, jsx, fragment }) {
const { BindingTwoWay, LabelGroup, Panel, SliderInput, SelectInput } = ReactPCUI;
const { BindingTwoWay, LabelGroup, Panel, SliderInput, SelectInput, ColorPicker } = ReactPCUI;

const [type, setType] = React.useState('translate');
const [proj, setProj] = React.useState(pc.PROJECTION_PERSPECTIVE);
Expand Down Expand Up @@ -69,6 +69,37 @@ export function controls({ observer, ReactPCUI, React, jsx, fragment }) {
})
)
),
jsx(
Panel,
{ headerText: 'Grid' },
jsx(
LabelGroup,
{ text: 'Size' },
jsx(SliderInput, {
binding: new BindingTwoWay(),
link: { observer, path: 'grid.size' },
min: 1,
max: 10,
precision: 0
})
),
jsx(
LabelGroup,
{ text: 'Color X' },
jsx(ColorPicker, {
binding: new BindingTwoWay(),
link: { observer, path: 'grid.colorX' }
})
),
jsx(
LabelGroup,
{ text: 'Color Z' },
jsx(ColorPicker, {
binding: new BindingTwoWay(),
link: { observer, path: 'grid.colorZ' }
})
)
),
jsx(
Panel,
{ headerText: 'Camera' },
Expand Down
23 changes: 22 additions & 1 deletion examples/src/examples/misc/editor.example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,14 @@ orbitCamera.distance = 5 * camera.camera?.aspectRatio;

// attach grid
app.root.addComponent('script');
const grid = app.root.script.create(Grid);
const grid = /** @type {Grid} */ (app.root.script.create(Grid));
grid.halfExtents = new pc.Vec2(4, 4);
grid.attach(camera.camera);
data.set('grid', {
size: 4,
colorX: Object.values(grid.colorX),
colorZ: Object.values(grid.colorZ)
});

// create light entity
const light = new pc.Entity('light');
Expand Down Expand Up @@ -227,6 +232,8 @@ window.addEventListener('keyup', keyup);
window.addEventListener('keypress', keypress);

// gizmo and camera set handler
const tmpVa = new pc.Vec2();
const tmpC1 = new pc.Color();
data.on('*:set', (/** @type {string} */ path, /** @type {any} */ value) => {
const [category, key] = path.split('.');
switch (category) {
Expand All @@ -253,6 +260,20 @@ data.on('*:set', (/** @type {string} */ path, /** @type {any} */ value) => {
gizmoHandler.gizmo[key] = value;
break;
}
case 'grid': {
switch (key) {
case 'size':
grid.halfExtents = tmpVa.set(value, value);
break;
case 'colorX':
grid.colorX = tmpC1.set(value[0], value[1], value[2]);
break;
case 'colorZ':
grid.colorZ = tmpC1.set(value[0], value[1], value[2]);
break;
}
break;
}
}
});

Expand Down

0 comments on commit fe77d48

Please sign in to comment.