mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-10 18:50:54 +00:00
Merge pull request #531 from lightest/grating_incorrect_mask_position
Proper positioning of the mask sprite for gratings.
This commit is contained in:
commit
24c08055a0
@ -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.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 {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 {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.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 {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.
|
* @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,
|
win,
|
||||||
mask,
|
mask,
|
||||||
pos,
|
pos,
|
||||||
|
anchor,
|
||||||
units,
|
units,
|
||||||
sf = 1.0,
|
sf = 1.0,
|
||||||
ori,
|
ori,
|
||||||
@ -313,7 +315,7 @@ export class GratingStim extends VisualStim
|
|||||||
maskParams
|
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({
|
this._adjustmentFilter = new AdjustmentFilter({
|
||||||
contrast
|
contrast
|
||||||
@ -741,9 +743,15 @@ export class GratingStim extends VisualStim
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 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);
|
const maskMesh = this._getPixiMeshFromPredefinedShaders(this._mask);
|
||||||
|
|
||||||
|
// Since maskMesh is centered around (0, 0) (has vertices going around it),
|
||||||
|
// offsetting maskMesh position to properly cover render target texture,
|
||||||
|
// which created with top-left corner at (0, 0).
|
||||||
|
maskMesh.position.set(this._size_px[0] * 0.5, this._size_px[1] * 0.5);
|
||||||
|
|
||||||
|
// For some reason setting PIXI.Mesh as .mask doesn't do anything,
|
||||||
|
// rendering mask to texture for further use.
|
||||||
const rt = PIXI.RenderTexture.create({
|
const rt = PIXI.RenderTexture.create({
|
||||||
width: this._size_px[0],
|
width: this._size_px[0],
|
||||||
height: this._size_px[1],
|
height: this._size_px[1],
|
||||||
@ -756,6 +764,8 @@ export class GratingStim extends VisualStim
|
|||||||
this._pixi.mask = maskSprite;
|
this._pixi.mask = maskSprite;
|
||||||
this._pixi.addChild(maskSprite);
|
this._pixi.addChild(maskSprite);
|
||||||
}
|
}
|
||||||
|
// Since grating 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
|
// 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