mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-25 15:08:11 +00:00
半球光帮助器。
This commit is contained in:
parent
021f033a7c
commit
f890208885
@ -4,6 +4,7 @@ import GridHelper from './GridHelper';
|
||||
import CameraHelper from './CameraHelper';
|
||||
import PointLightHelpers from './light/PointLightHelpers';
|
||||
import DirectionalLightHelpers from './light/DirectionalLightHelpers';
|
||||
import HemisphereLightHelpers from './light/HemisphereLightHelpers';
|
||||
|
||||
import ViewHelper from './ViewHelper';
|
||||
import SelectHelper from './SelectHelper';
|
||||
@ -21,6 +22,7 @@ function Helpers(app) {
|
||||
new CameraHelper(app),
|
||||
new PointLightHelpers(app),
|
||||
new DirectionalLightHelpers(app),
|
||||
new HemisphereLightHelpers(app),
|
||||
|
||||
new SelectHelper(app),
|
||||
new ViewHelper(app),
|
||||
|
||||
@ -0,0 +1,76 @@
|
||||
import BaseHelper from '../BaseHelper';
|
||||
import VolumeHemisphereLightHelper from './VolumeHemisphereLightHelper';
|
||||
|
||||
/**
|
||||
* 半球光帮助器
|
||||
* @param {*} app
|
||||
*/
|
||||
function HemisphereLightHelpers(app) {
|
||||
BaseHelper.call(this, app);
|
||||
|
||||
this.helpers = [];
|
||||
}
|
||||
|
||||
HemisphereLightHelpers.prototype = Object.create(BaseHelper.prototype);
|
||||
HemisphereLightHelpers.prototype.constructor = HemisphereLightHelpers;
|
||||
|
||||
HemisphereLightHelpers.prototype.start = function () {
|
||||
this.app.on(`objectAdded.${this.id}`, this.onObjectAdded.bind(this));
|
||||
this.app.on(`objectRemoved.${this.id}`, this.onObjectRemoved.bind(this));
|
||||
this.app.on(`objectChanged.${this.id}`, this.onObjectChanged.bind(this));
|
||||
};
|
||||
|
||||
HemisphereLightHelpers.prototype.stop = function () {
|
||||
this.app.on(`objectAdded.${this.id}`, null);
|
||||
this.app.on(`objectRemoved.${this.id}`, null);
|
||||
this.app.on(`objectChanged.${this.id}`, null);
|
||||
};
|
||||
|
||||
HemisphereLightHelpers.prototype.onObjectAdded = function (object) {
|
||||
if (!object.isHemisphereLight) {
|
||||
return;
|
||||
}
|
||||
|
||||
var helper = new VolumeHemisphereLightHelper(object, 1);
|
||||
|
||||
this.helpers.push(helper);
|
||||
|
||||
this.app.editor.sceneHelpers.add(helper);
|
||||
};
|
||||
|
||||
HemisphereLightHelpers.prototype.onObjectRemoved = function (object) {
|
||||
if (!object.isHemisphereLight) {
|
||||
return;
|
||||
}
|
||||
|
||||
var index = this.helpers.findIndex(n => {
|
||||
return n.light === object;
|
||||
});
|
||||
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.app.editor.sceneHelpers.remove(this.helpers[index]);
|
||||
this.helpers[index].dispose();
|
||||
|
||||
this.helpers.splice(index, 1);
|
||||
};
|
||||
|
||||
HemisphereLightHelpers.prototype.onObjectChanged = function (object) {
|
||||
if (!object.isHemisphereLight) {
|
||||
return;
|
||||
}
|
||||
|
||||
var index = this.helpers.findIndex(n => {
|
||||
return n.light === object;
|
||||
});
|
||||
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.helpers[index].update();
|
||||
};
|
||||
|
||||
export default HemisphereLightHelpers;
|
||||
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 具有一定体积的半球光帮助器
|
||||
* @param {*} light
|
||||
* @param {*} size
|
||||
* @param {*} color
|
||||
*/
|
||||
function VolumeHemisphereLightHelper(light, size, color) {
|
||||
THREE.HemisphereLightHelper.call(this, light, size, color);
|
||||
|
||||
var geometry = new THREE.SphereBufferGeometry(2, 4, 2);
|
||||
var material = new THREE.MeshBasicMaterial({
|
||||
color: 0xff0000,
|
||||
visible: false
|
||||
});
|
||||
|
||||
this.picker = new THREE.Mesh(geometry, material);
|
||||
this.picker.name = 'picker';
|
||||
this.add(this.picker);
|
||||
}
|
||||
|
||||
VolumeHemisphereLightHelper.prototype = Object.create(THREE.HemisphereLightHelper.prototype);
|
||||
VolumeHemisphereLightHelper.prototype.constructor = VolumeHemisphereLightHelper;
|
||||
|
||||
VolumeHemisphereLightHelper.prototype.raycast = function (raycaster, intersects) {
|
||||
var intersect = raycaster.intersectObject(this.picker)[0];
|
||||
if (intersect) {
|
||||
intersect.object = this.light;
|
||||
intersects.push(intersect);
|
||||
}
|
||||
};
|
||||
|
||||
VolumeHemisphereLightHelper.prototype.dispose = function () {
|
||||
this.remove(this.picker);
|
||||
|
||||
this.picker.geometry.dispose();
|
||||
this.picker.material.dispose();
|
||||
delete this.picker;
|
||||
|
||||
THREE.HemisphereLightHelper.prototype.dispose.call(this);
|
||||
};
|
||||
|
||||
export default VolumeHemisphereLightHelper;
|
||||
Loading…
x
Reference in New Issue
Block a user