Skip to content

Commit

Permalink
Comments, function name updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Jul 19, 2024
1 parent 38eaf5b commit 99893bd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/three/loaders/gltf/metadata/classes/MeshFeatures.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Vector2 } from 'three';
import { TextureReadUtility } from '../utilities/TextureReadUtility.js';
import { getTexCoord, getTexelIndices, getTriangleIndices } from '../utilities/TexCoordUtilities.js';
import { getTexCoord, getTexelIndices, getTriangleVertexIndices } from '../utilities/TexCoordUtilities.js';

const _uv = /* @__PURE__ */ new Vector2();
const _pixel = /* @__PURE__ */ new Vector2();
Expand Down Expand Up @@ -96,7 +96,7 @@ export class MeshFeatures {
TextureReadUtility.increaseSizeTo( width );

// get the attribute indices
const indices = getTriangleIndices( geometry, triangle );
const indices = getTriangleVertexIndices( geometry, triangle );
const closestIndex = indices[ getMaxBarycoordIndex( barycoord ) ];
for ( let i = 0, l = featureIds.length; i < l; i ++ ) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Vector2 } from 'three';
import { PropertySetAccessor } from './PropertySetAccessor.js';
import { ClassProperty } from './ClassProperty.js';
import { TextureReadUtility } from '../utilities/TextureReadUtility.js';
import { getTexCoord, getTexelIndices, getTriangleIndices } from '../utilities/TexCoordUtilities.js';
import { getTexCoord, getTexelIndices, getTriangleVertexIndices } from '../utilities/TexCoordUtilities.js';
import {
initializeFromClass,
initializeFromProperty,
Expand Down Expand Up @@ -95,7 +95,7 @@ export class PropertyTextureAccessor extends PropertySetAccessor {
const textures = this.data;
const accessorProperties = this.definition.properties;
const properties = this.properties;
const indices = getTriangleIndices( geometry, faceIndex );
const indices = getTriangleVertexIndices( geometry, faceIndex );
for ( let i = 0, l = names.length; i < l; i ++ ) {

// skip any requested properties that are not provided
Expand Down
14 changes: 10 additions & 4 deletions src/three/loaders/gltf/metadata/utilities/TexCoordUtilities.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Vector2 } from 'three';

const _uv0 = /* @__PURE__ */ new Vector2();
const _uv1 = /* @__PURE__ */ new Vector2();
const _uv2 = /* @__PURE__ */ new Vector2();

// returns the uv attribute of the given index
export function getTextureCoordAttribute( geometry, index ) {

if ( index === 0 ) {
Expand All @@ -14,7 +19,8 @@ export function getTextureCoordAttribute( geometry, index ) {

}

export function getTriangleIndices( geometry, faceIndex, target = new Array( 3 ) ) {
// returns the vertex indices associated with the triangle index
export function getTriangleVertexIndices( geometry, faceIndex, target = new Array( 3 ) ) {

// get the attribute indices
let i0 = 3 * faceIndex;
Expand All @@ -35,9 +41,8 @@ export function getTriangleIndices( geometry, faceIndex, target = new Array( 3 )

}

const _uv0 = new Vector2();
const _uv1 = new Vector2();
const _uv2 = new Vector2();
// takes a tex coord index, barycoord, vertex indices, and target to set
// sets target to the interpolated uv value
export function getTexCoord( geometry, texCoord, barycoord, indices, target ) {

const [ i0, i1, i2 ] = indices;
Expand All @@ -54,6 +59,7 @@ export function getTexCoord( geometry, texCoord, barycoord, indices, target ) {

}

// gets the x, y index of the pixel at the given uv coordinate
export function getTexelIndices( uv, width, height, target ) {

const fx = uv.x - Math.floor( uv.x );
Expand Down
12 changes: 9 additions & 3 deletions src/three/loaders/gltf/metadata/utilities/TextureReadUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ const _box = /* @__PURE__ */ new Box2();
const _currentScissor = /* @__PURE__ */ new Vector4();
const _pos = /* @__PURE__ */ new Vector2();

// Utility for reading sets of individual pixel values from textures
export const TextureReadUtility = new ( class {

constructor() {

// TODO: is it possible for the textures to be a type other than UInt8?
this._renderer = new WebGLRenderer();
this._target = new WebGLRenderTarget( 1, 1 );
this._texTarget = new WebGLRenderTarget();

// quad to render just a single pixel from the provided texture
this._quad = new FullScreenQuad( new ShaderMaterial( {

blending: CustomBlending,
Expand Down Expand Up @@ -51,12 +53,14 @@ export const TextureReadUtility = new ( class {

}

// increases the width of the target render target to support more data
increaseSizeTo( width ) {

this._target.setSize( Math.max( this._target.width, width ), 1 );

}

// read data from the rendered texture asynchronously
readDataAsync( buffer ) {

const { _renderer, _target } = this;
Expand All @@ -72,21 +76,23 @@ export const TextureReadUtility = new ( class {

}

// read data from the rendered texture
readData( buffer ) {

const { _renderer, _target } = this;
_renderer.readRenderTargetPixels( _target, 0, 0, buffer.length / 4, 1, buffer );

}

// render a single pixel from the source at the destination point on the
// render target
// render a single pixel from the source at the destination point on the render target
// takes the texture, pixel to read from, and pixel to render in to
renderPixelToTarget( texture, pixel, dstPixel ) {

const { _quad, _renderer, _target, _texTarget } = this;

if ( REVISION_166 ) {

// copies the pixel directly to the target buffer
_box.min.copy( pixel );
_box.max.copy( pixel );
_box.max.x += 1;
Expand Down

0 comments on commit 99893bd

Please sign in to comment.