mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-10 10:40:54 +00:00
Fix for incorrect mask position, when grating vertices centered around (0, 0);
This commit is contained in:
parent
f483f6de1c
commit
25aef3d500
@ -279,6 +279,7 @@ export class GratingStim extends VisualStim
|
||||
* @param {number} [options.sf=1.0] - spatial frequency of the function used in grating stimulus
|
||||
* @param {number} [options.phase=0.0] - phase of the function used in grating stimulus, multiples of period of that function
|
||||
* @param {Array.<number>} [options.pos= [0, 0]] - the position of the center of the stimulus
|
||||
* @param {string} [options.anchor = "center"] - sets the origin point of the stim
|
||||
* @param {number} [options.ori= 0.0] - the orientation (in degrees)
|
||||
* @param {number} [options.size] - the size of the rendered image (DEFAULT_STIM_SIZE_PX will be used if size is not specified)
|
||||
* @param {Color} [options.color= "white"] - Foreground color of the stimulus. Can be String like "red" or "#ff0000" or Number like 0xff0000.
|
||||
@ -296,6 +297,7 @@ export class GratingStim extends VisualStim
|
||||
win,
|
||||
mask,
|
||||
pos,
|
||||
anchor,
|
||||
units,
|
||||
sf = 1.0,
|
||||
ori,
|
||||
@ -313,7 +315,7 @@ export class GratingStim extends VisualStim
|
||||
maskParams
|
||||
} = {})
|
||||
{
|
||||
super({ name, win, units, ori, opacity, depth, pos, size, autoDraw, autoLog });
|
||||
super({ name, win, units, ori, opacity, depth, pos, anchor, size, autoDraw, autoLog });
|
||||
|
||||
this._adjustmentFilter = new AdjustmentFilter({
|
||||
contrast
|
||||
@ -741,9 +743,13 @@ export class GratingStim extends VisualStim
|
||||
}
|
||||
else
|
||||
{
|
||||
// for some reason setting PIXI.Mesh as .mask doesn't do anything,
|
||||
// For some reason setting PIXI.Mesh as .mask doesn't do anything,
|
||||
// rendering mask to texture for further use.
|
||||
const maskMesh = this._getPixiMeshFromPredefinedShaders(this._mask);
|
||||
|
||||
// Since mesh is centered around [0, 0] (has vertices going around it),
|
||||
// offsetting maskMesh position to properly cover render target texture.
|
||||
maskMesh.position.set(this._size_px[0] * 0.5, this._size_px[1] * 0.5);
|
||||
const rt = PIXI.RenderTexture.create({
|
||||
width: this._size_px[0],
|
||||
height: this._size_px[1],
|
||||
@ -756,6 +762,8 @@ export class GratingStim extends VisualStim
|
||||
this._pixi.mask = maskSprite;
|
||||
this._pixi.addChild(maskSprite);
|
||||
}
|
||||
// Since mesh is centered around [0, 0], setting mask's anchor to center to properly cover target image.
|
||||
this._pixi.mask.anchor.set(0.5);
|
||||
}
|
||||
|
||||
// since _pixi.width may not be immediately available but the rest of the code needs its value
|
||||
|
Loading…
Reference in New Issue
Block a user