Skip to content

Commit

Permalink
[core] Split texture.ts. (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
Don McCurdy committed Aug 15, 2020
1 parent ce341a3 commit 4dbd60f
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 131 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/properties/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ export * from './root';
export * from './scene';
export * from './skin';
export * from './texture';
export * from './texture-info';
export * from './texture-sampler';
4 changes: 3 additions & 1 deletion packages/core/src/properties/property-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { Accessor } from './accessor';
import { ExtensionProperty } from './extension-property';
import { Material } from './material';
import { Primitive, PrimitiveTarget } from './mesh';
import { Texture, TextureInfo, TextureSampler } from './texture';
import { Texture } from './texture';
import { TextureInfo } from './texture-info';
import { TextureSampler } from './texture-sampler';

/** @hidden */
export class TextureLink extends Link<Material|ExtensionProperty, Texture> {
Expand Down
34 changes: 34 additions & 0 deletions packages/core/src/properties/texture-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { PropertyType } from '../constants';

/**
* # TextureInfo
*
* *Settings associated with a particular use of a {@link Texture}.*
*
* Different materials may reuse the same texture but with different texture coordinates. For other
* settings affecting application of a texture, see {@link TextureSampler}.
*
* References:
* - [glTF → Texture Info](https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#reference-textureinfo)
*
* @category Properties
*/
export class TextureInfo {
public readonly propertyType = PropertyType.TEXTURE_INFO;

private texCoord = 0;

public copy(other: this): this {
this.texCoord = other.texCoord;
return this;
}

/** Returns the texture coordinate (UV set) index for the texture. */
public getTexCoord(): number { return this.texCoord; }

/** Sets the texture coordinate (UV set) index for the texture. */
public setTexCoord(texCoord: number): this {
this.texCoord = texCoord;
return this;
}
}
98 changes: 98 additions & 0 deletions packages/core/src/properties/texture-sampler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { PropertyType } from '../constants';

/**
* # TextureSampler
*
* *Settings associated with a particular use of a {@link Texture}.*
*
* Different materials may reuse the same texture but with different texture coordinates. For other
* settings affecting application of a texture, see {@link TextureInfo}.
*
* References:
* - [glTF → Samplers](https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#samplers)
*
* @category Properties
*/
export class TextureSampler {
public readonly propertyType = PropertyType.TEXTURE_SAMPLER;

private _magFilter: GLTF.TextureMagFilter = null;
private _minFilter: GLTF.TextureMinFilter = null;
private _wrapS: GLTF.TextureWrapMode = GLTF.TextureWrapMode.REPEAT;
private _wrapT: GLTF.TextureWrapMode = GLTF.TextureWrapMode.REPEAT;

public copy(other: this): this {
this._magFilter = other._magFilter;
this._minFilter = other._minFilter;
this._wrapS = other._wrapS;
this._wrapT = other._wrapT;
return this;
}

/** UV wrapping mode. Values correspond to WebGL enums. */
public static TextureWrapMode = {
CLAMP_TO_EDGE: GLTF.TextureWrapMode.CLAMP_TO_EDGE,
MIRRORED_REPEAT: GLTF.TextureWrapMode.MIRRORED_REPEAT,
REPEAT: GLTF.TextureWrapMode.REPEAT,
}

/** Magnification filter. Values correspond to WebGL enums. */
public static TextureMagFilter = {
NEAREST: GLTF.TextureMagFilter.NEAREST,
LINEAR: GLTF.TextureMagFilter.LINEAR,
}

/** Minification filter. Values correspond to WebGL enums. */
public static TextureMinFilter = {
NEAREST: GLTF.TextureMinFilter.NEAREST,
LINEAR: GLTF.TextureMinFilter.LINEAR,
NEAREST_MIPMAP_NEAREST: GLTF.TextureMinFilter.NEAREST_MIPMAP_NEAREST,
LINEAR_MIPMAP_NEAREST: GLTF.TextureMinFilter.LINEAR_MIPMAP_NEAREST,
NEAREST_MIPMAP_LINEAR: GLTF.TextureMinFilter.NEAREST_MIPMAP_LINEAR,
LINEAR_MIPMAP_LINEAR: GLTF.TextureMinFilter.LINEAR_MIPMAP_LINEAR,
}

/**********************************************************************************************
* Min/mag filter.
*/

/** Returns the magnification filter applied to the texture. */
public getMagFilter(): GLTF.TextureMagFilter { return this._magFilter; }

/** Sets the magnification filter applied to the texture. */
public setMagFilter(magFilter: GLTF.TextureMagFilter): this {
this._magFilter = magFilter;
return this;
}

/** Sets the minification filter applied to the texture. */
public getMinFilter(): GLTF.TextureMinFilter { return this._minFilter; }

/** Returns the minification filter applied to the texture. */
public setMinFilter(minFilter: GLTF.TextureMinFilter): this {
this._minFilter = minFilter;
return this;
}

/**********************************************************************************************
* UV wrapping.
*/

/** Returns the S (U) wrapping mode for UVs used by the texture. */
public getWrapS(): GLTF.TextureWrapMode { return this._wrapS; }

/** Sets the S (U) wrapping mode for UVs used by the texture. */
public setWrapS(wrapS: GLTF.TextureWrapMode): this {
this._wrapS = wrapS;
return this;
}

/** Returns the T (V) wrapping mode for UVs used by the texture. */
public getWrapT(): GLTF.TextureWrapMode { return this._wrapT; }

/** Sets the T (V) wrapping mode for UVs used by the texture. */
public setWrapT(wrapT: GLTF.TextureWrapMode): this {
this._wrapT = wrapT;
return this;
}
}
130 changes: 0 additions & 130 deletions packages/core/src/properties/texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,133 +107,3 @@ export class Texture extends ExtensibleProperty {
: ImageUtils.getSizeJPEG(this.image);
}
}

/**
* # TextureInfo
*
* *Settings associated with a particular use of a {@link Texture}.*
*
* Different materials may reuse the same texture but with different texture coordinates. For other
* settings affecting application of a texture, see {@link TextureSampler}.
*
* References:
* - [glTF → Texture Info](https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#reference-textureinfo)
*
* @category Properties
*/
export class TextureInfo {
public readonly propertyType = PropertyType.TEXTURE_INFO;

private texCoord = 0;

public copy(other: this): this {
this.texCoord = other.texCoord;
return this;
}

/** Returns the texture coordinate (UV set) index for the texture. */
public getTexCoord(): number { return this.texCoord; }

/** Sets the texture coordinate (UV set) index for the texture. */
public setTexCoord(texCoord: number): this {
this.texCoord = texCoord;
return this;
}
}

/**
* # TextureSampler
*
* *Settings associated with a particular use of a {@link Texture}.*
*
* Different materials may reuse the same texture but with different texture coordinates. For other
* settings affecting application of a texture, see {@link TextureInfo}.
*
* References:
* - [glTF → Samplers](https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#samplers)
*
* @category Properties
*/
export class TextureSampler {
public readonly propertyType = PropertyType.TEXTURE_SAMPLER;

private _magFilter: GLTF.TextureMagFilter = null;
private _minFilter: GLTF.TextureMinFilter = null;
private _wrapS: GLTF.TextureWrapMode = GLTF.TextureWrapMode.REPEAT;
private _wrapT: GLTF.TextureWrapMode = GLTF.TextureWrapMode.REPEAT;

public copy(other: this): this {
this._magFilter = other._magFilter;
this._minFilter = other._minFilter;
this._wrapS = other._wrapS;
this._wrapT = other._wrapT;
return this;
}

/** UV wrapping mode. Values correspond to WebGL enums. */
public static TextureWrapMode = {
CLAMP_TO_EDGE: GLTF.TextureWrapMode.CLAMP_TO_EDGE,
MIRRORED_REPEAT: GLTF.TextureWrapMode.MIRRORED_REPEAT,
REPEAT: GLTF.TextureWrapMode.REPEAT,
}

/** Magnification filter. Values correspond to WebGL enums. */
public static TextureMagFilter = {
NEAREST: GLTF.TextureMagFilter.NEAREST,
LINEAR: GLTF.TextureMagFilter.LINEAR,
}

/** Minification filter. Values correspond to WebGL enums. */
public static TextureMinFilter = {
NEAREST: GLTF.TextureMinFilter.NEAREST,
LINEAR: GLTF.TextureMinFilter.LINEAR,
NEAREST_MIPMAP_NEAREST: GLTF.TextureMinFilter.NEAREST_MIPMAP_NEAREST,
LINEAR_MIPMAP_NEAREST: GLTF.TextureMinFilter.LINEAR_MIPMAP_NEAREST,
NEAREST_MIPMAP_LINEAR: GLTF.TextureMinFilter.NEAREST_MIPMAP_LINEAR,
LINEAR_MIPMAP_LINEAR: GLTF.TextureMinFilter.LINEAR_MIPMAP_LINEAR,
}

/**********************************************************************************************
* Min/mag filter.
*/

/** Returns the magnification filter applied to the texture. */
public getMagFilter(): GLTF.TextureMagFilter { return this._magFilter; }

/** Sets the magnification filter applied to the texture. */
public setMagFilter(magFilter: GLTF.TextureMagFilter): this {
this._magFilter = magFilter;
return this;
}

/** Sets the minification filter applied to the texture. */
public getMinFilter(): GLTF.TextureMinFilter { return this._minFilter; }

/** Returns the minification filter applied to the texture. */
public setMinFilter(minFilter: GLTF.TextureMinFilter): this {
this._minFilter = minFilter;
return this;
}

/**********************************************************************************************
* UV wrapping.
*/

/** Returns the S (U) wrapping mode for UVs used by the texture. */
public getWrapS(): GLTF.TextureWrapMode { return this._wrapS; }

/** Sets the S (U) wrapping mode for UVs used by the texture. */
public setWrapS(wrapS: GLTF.TextureWrapMode): this {
this._wrapS = wrapS;
return this;
}

/** Returns the T (V) wrapping mode for UVs used by the texture. */
public getWrapT(): GLTF.TextureWrapMode { return this._wrapT; }

/** Sets the T (V) wrapping mode for UVs used by the texture. */
public setWrapT(wrapT: GLTF.TextureWrapMode): this {
this._wrapT = wrapT;
return this;
}
}

0 comments on commit 4dbd60f

Please sign in to comment.