untitled-game-engine/src/plugins/renderer/engine/webgpu/mesh/mesh.js
2025-03-31 12:36:07 -05:00

65 lines
1.7 KiB
JavaScript

import { MeshAttributeData } from './vertex.js'
import { Indices } from './index.js'
import { assignOptions } from '/src/utils/index.js'
export const PrimitiveTopology = Object.freeze({
PointList: 'point-list',
LineList: 'line-list',
LineStrip: 'line-strip',
TriangleList: 'triangle-list',
TriangleStrip: 'triangle-strip'
})
export const IndexFormat = Object.freeze({
Uint16: 'uint16',
Uint32: 'uint32'
})
export const FrontFace = Object.freeze({
Ccw: 'ccw',
Cw: 'cw'
})
export const CullMode = Object.freeze({
None: 'none',
Front: 'front',
Back: 'back'
})
export class PrimitiveState {
#topology = PrimitiveTopology.TriangleList
#stripIndexFormat
#frontFace = FrontFace.Ccw
#cullMode = CullMode.None
#unclippedDepth = false
/**
* @param {GPUIndexFormat} stripIndexFormat
* @param {Object} options
* @param {GPUPrimitiveTopology} [options.topology]
* @param {GPUFrontFace} [options.frontFace]
* @param {GPUCullMode} [options.cullMode]
* @param {boolean} [options.unclippedDepth]
*/
constructor(stripIndexFormat, options) {
this.#stripIndexFormat = stripIndexFormat
assignOptions(this, options)
}
get topology() { return this.#topology }
get stripIndexFormat() { return this.#stripIndexFormat }
get frontFace() { return this.#frontFace }
get cullMode() { return this.#cullMode }
get unclippedDepth() { return this.#unclippedDepth }
}
export class Mesh {
/** @type {PrimitiveTopology} */
topology
/** @type {Map<VertexAttributeId, MeshAttributeData>} */
attributes = new Map()
/** @type {Indices} */
indices
}