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

Audio zones transform fix and new shapes #1208

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
66 changes: 58 additions & 8 deletions src/editor/nodes/AudioZoneNode.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import { Material, BoxBufferGeometry, Mesh, BoxHelper } from "three";
import {
Material,
BoxBufferGeometry,
LineSegments,
EdgesGeometry,
BoxGeometry,
SphereGeometry,
LineBasicMaterial,
Quaternion
} from "three";
import AudioParams, { AudioElementType } from "../objects/AudioParams";
import AudioParamsNode from "./AudioParamsNode";

const requiredProperties = ["enabled", "inOut", "outIn"];

const DEBUG_BBAA_COLOR = 0x49ef4;
const debugMaterial = new LineBasicMaterial({
color: DEBUG_BBAA_COLOR,
linewidth: 2
});

export const AudioZoneShape = Object.freeze({
Box: "box",
Sphere: "sphere"
});

export default class AudioZoneNode extends AudioParamsNode(AudioParams) {
static componentName = "audio-zone";

Expand Down Expand Up @@ -35,23 +55,50 @@ export default class AudioZoneNode extends AudioParamsNode(AudioParams) {
node.enabled = zoneProps.enabled;
node.inOut = zoneProps.inOut;
node.outIn = zoneProps.outIn;
node.shape = zoneProps.shape || AudioZoneShape.Box;

return node;
}

constructor(editor) {
super(editor, AudioElementType.AUDIO_ZONE);

const boxMesh = new Mesh(AudioZoneNode._geometry, AudioZoneNode._material);
const box = new BoxHelper(boxMesh, 0x00ff00);
box.layers.set(1);
this.helper = box;
this.add(box);
this.enabled = true;
this.inOut = true;
this.outIn = true;
this.shape = AudioZoneShape.Box;
}

set shape(shape) {
this._shape = shape;

this.remove(this.helper);
let geo;
if (shape === AudioZoneShape.Box) {
geo = new BoxGeometry();
} else {
geo = new SphereGeometry();
}
const debugMesh = new LineSegments(new EdgesGeometry(geo), debugMaterial);
debugMesh.layers.set(1);
this.helper = debugMesh;
this.add(debugMesh);
this.matrixAutoUpdate = false;
}

get shape() {
return this._shape;
}

onUpdate = (function() {
const quat = new Quaternion();
return function() {
this.quaternion.set(0, 0, 0, 1);
this.quaternion.multiply(this.parent.getWorldQuaternion(quat).inverse());
keianhzo marked this conversation as resolved.
Show resolved Hide resolved
this.updateMatrix();
};
})();

copy(source, recursive = true) {
if (recursive) {
this.remove(this.helper);
Expand All @@ -70,6 +117,7 @@ export default class AudioZoneNode extends AudioParamsNode(AudioParams) {
this.enabled = source.enabled;
this.inOut = source.inOut;
this.outIn = source.outIn;
this._shape = source.shape;

return this;
}
Expand All @@ -79,7 +127,8 @@ export default class AudioZoneNode extends AudioParamsNode(AudioParams) {
"audio-zone": {
enabled: this.enabled,
inOut: this.inOut,
outIn: this.outIn
outIn: this.outIn,
shape: this.shape
}
});
}
Expand All @@ -99,7 +148,8 @@ export default class AudioZoneNode extends AudioParamsNode(AudioParams) {
target: this.gltfIndexForUUID(this.target),
enabled: this.enabled,
inOut: this.inOut,
outIn: this.outIn
outIn: this.outIn,
shape: this.shape
});
}
}
14 changes: 14 additions & 0 deletions src/ui/properties/AudioZoneNodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import BooleanInput from "../inputs/BooleanInput";
import { DiceD6 } from "styled-icons/fa-solid/DiceD6";
import AudioParamsProperties from "./AudioParamsProperties";
import { SourceType } from "../../editor/objects/AudioParams";
import SelectInput from "../inputs/SelectInput";
import { AudioZoneShape } from "../../editor/nodes/AudioZoneNode";

export const AudioZoneShapeOptions = Object.keys(AudioZoneShape).map(k => ({
label: k,
value: AudioZoneShape[k]
}));

export default class AudioZoneNodeEditor extends Component {
static propTypes = {
Expand Down Expand Up @@ -38,6 +45,10 @@ export default class AudioZoneNodeEditor extends Component {
this.props.editor.setPropertySelected("outIn", value);
};

onChangeShape = value => {
this.props.editor.setPropertySelected("shape", value);
};

componentDidMount() {
const options = [];

Expand Down Expand Up @@ -72,6 +83,9 @@ export default class AudioZoneNodeEditor extends Component {
>
<BooleanInput value={node.outIn} onChange={this.onChangeOutIn} />
</InputGroup>
<InputGroup name="Shape" info="Shape of the Audio Zone.">
<SelectInput options={AudioZoneShapeOptions} value={node.shape} onChange={this.onChangeShape} />
</InputGroup>
<AudioParamsProperties sourceType={SourceType.AUDIO_ZONE} {...this.props} />
</NodeEditor>
);
Expand Down
3 changes: 3 additions & 0 deletions test/integration/snapshots/Editor.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -4477,6 +4477,7 @@ Generated by [AVA](https://avajs.dev).
enabled: true,
inOut: true,
outIn: true,
shape: 'box',
},
},
{
Expand Down Expand Up @@ -6254,6 +6255,7 @@ Generated by [AVA](https://avajs.dev).
enabled: true,
inOut: true,
outIn: true,
shape: 'box',
},
},
{
Expand Down Expand Up @@ -7972,6 +7974,7 @@ Generated by [AVA](https://avajs.dev).
enabled: true,
inOut: true,
outIn: true,
shape: 'box',
},
},
{
Expand Down
Binary file modified test/integration/snapshots/Editor.test.js.snap
Binary file not shown.