mirror of
https://github.com/pissang/claygl.git
synced 2026-02-01 17:27:08 +00:00
fix ray picking and other stuffs.
This commit is contained in:
parent
bf5b985e02
commit
765ea90194
@ -76,7 +76,7 @@ class Camera extends ClayNode {
|
||||
* @param {clay.Ray} [out]
|
||||
* @return {clay.Ray}
|
||||
*/
|
||||
castRay(ndc: Vector2, out: Ray) {
|
||||
castRay(ndc: Vector2, out?: Ray) {
|
||||
const ray = out !== undefined ? out : new Ray();
|
||||
const x = ndc.array[0];
|
||||
const y = ndc.array[1];
|
||||
|
||||
@ -364,8 +364,8 @@ class Renderer extends Notifier {
|
||||
}
|
||||
this.gl.targetRenderer = this;
|
||||
|
||||
this._width = opts.width || 100;
|
||||
this._height = opts.height || 100;
|
||||
this._width = opts.width || canvas.width || 100;
|
||||
this._height = opts.height || canvas.height || 100;
|
||||
this._devicePixelRatio =
|
||||
opts.devicePixelRatio || (typeof window !== 'undefined' ? window.devicePixelRatio : 1.0);
|
||||
this.resize(this._width, this._height);
|
||||
@ -1527,7 +1527,7 @@ class Renderer extends Notifier {
|
||||
* @param {clay.Vector2} [out]
|
||||
* @return {clay.Vector2}
|
||||
*/
|
||||
screenToNDC(x: number, y: number, out: Vector2): Vector2 {
|
||||
screenToNDC(x: number, y: number, out?: Vector2): Vector2 {
|
||||
if (!out) {
|
||||
out = new Vector2();
|
||||
}
|
||||
|
||||
@ -55,6 +55,10 @@ interface TextureCube extends TextureCubeOpts {}
|
||||
class TextureCube extends Texture {
|
||||
readonly textureType = 'textureCube';
|
||||
|
||||
constructor(opts?: Partial<TextureCubeOpts>) {
|
||||
super(opts);
|
||||
}
|
||||
|
||||
get width() {
|
||||
const images = this.image;
|
||||
if (images && images.px) {
|
||||
|
||||
@ -80,7 +80,7 @@ export {
|
||||
} from './shader/index';
|
||||
|
||||
// Picking
|
||||
export { pick as pickByRay } from './picking/rayPicking';
|
||||
export { pick as pickByRay, pickAll as pickAllByRay } from './picking/rayPicking';
|
||||
export { default as PixelPicking } from './picking/PixelPicking';
|
||||
|
||||
// GLTF Loader
|
||||
|
||||
@ -4,6 +4,7 @@ import Vector3 from '../math/Vector3';
|
||||
export interface TubeLightOpts extends LightOpts {
|
||||
range: number;
|
||||
radius: number;
|
||||
length: number;
|
||||
}
|
||||
|
||||
class TubeLight extends Light {
|
||||
|
||||
@ -32,7 +32,7 @@ export function matrixOrVectorClassToString(obj: { array: number[] }, cols: numb
|
||||
const Clz = obj.constructor;
|
||||
const className = (Clz && Clz.name) || '';
|
||||
for (let i = 0; i < Math.ceil(array.length / cols); i++) {
|
||||
str += array.slice(i * cols, (i + 1) * cols).join('\t') + '\n';
|
||||
str += array.slice(i * cols, (i + 1) * cols).join('\t');
|
||||
}
|
||||
return className + '[\n' + str + '\n]';
|
||||
}
|
||||
|
||||
@ -58,7 +58,9 @@ class ParticleEmitter {
|
||||
amount = 20;
|
||||
|
||||
_particlePool: Particle[] = [];
|
||||
constructor() {
|
||||
constructor(opts?: Partial<ParticleEmitterOpts>) {
|
||||
Object.assign(this, opts);
|
||||
|
||||
// TODO Reduce heap memory
|
||||
for (let i = 0; i < this.max; i++) {
|
||||
const particle = new Particle();
|
||||
|
||||
@ -77,8 +77,10 @@ class ParticleRenderable extends Renderable {
|
||||
private _fields: ParticleField[] = [];
|
||||
private _particles: Particle[] = [];
|
||||
|
||||
constructor(opts: Partial<ParticleRenderableOpts>) {
|
||||
constructor(opts?: Partial<ParticleRenderableOpts>) {
|
||||
super(opts);
|
||||
opts = opts || {};
|
||||
|
||||
Object.assign(this, opts);
|
||||
this.geometry = new Geometry({
|
||||
dynamic: true
|
||||
|
||||
@ -95,13 +95,13 @@ const worldInverse = new Matrix4();
|
||||
function intersectRenderable(
|
||||
renderer: Renderer,
|
||||
camera: Camera,
|
||||
ray: Ray,
|
||||
rawRay: Ray,
|
||||
ndc: Vector2,
|
||||
renderable: Renderable,
|
||||
out: Intersection[]
|
||||
) {
|
||||
const isSkinnedMesh = renderable.isSkinnedMesh();
|
||||
ray.copy(ray);
|
||||
ray.copy(rawRay);
|
||||
Matrix4.invert(worldInverse, renderable.worldTransform);
|
||||
|
||||
// Skinned mesh will ignore the world transform.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user