Просмотр исходного кода

Add constructor params and type for generators in plugin-geometry-generator

master
Palash Bansal 1 год назад
Родитель
Сommit
c91754d1f6
Аккаунт пользователя с таким Email не найден

+ 2
- 2
plugins/geometry-generator/package-lock.json Просмотреть файл

{ {
"name": "@threepipe/plugin-geometry-generator", "name": "@threepipe/plugin-geometry-generator",
"version": "0.3.2",
"version": "0.3.3",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@threepipe/plugin-geometry-generator", "name": "@threepipe/plugin-geometry-generator",
"version": "0.3.2",
"version": "0.3.3",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"threepipe": "file:./../../src/" "threepipe": "file:./../../src/"

+ 2
- 2
plugins/geometry-generator/package.json Просмотреть файл

{ {
"name": "@threepipe/plugin-geometry-generator", "name": "@threepipe/plugin-geometry-generator",
"description": "Geometry generator plugin to create updatable parametric objects/geometries.", "description": "Geometry generator plugin to create updatable parametric objects/geometries.",
"version": "0.3.2",
"version": "0.3.3",
"devDependencies": { "devDependencies": {
}, },
"dependencies": { "dependencies": {
"replace": { "replace": {
"dependencies": {}, "dependencies": {},
"peerDependencies": { "peerDependencies": {
"threepipe": "^0.0.39"
"threepipe": "^0.0.40"
} }
} }
}, },

+ 6
- 5
plugins/geometry-generator/src/AGeometryGenerator.ts Просмотреть файл

createUiConfig?(geometry: IGeometry): UiObjectConfig[] createUiConfig?(geometry: IGeometry): UiObjectConfig[]
} }


function updateAttribute<T extends BufferAttribute=Float32BufferAttribute>(geometry: BufferGeometry, attribute: string, itemSize: number, array: any[], cls?: Class<T>) {
function updateAttribute<T extends BufferAttribute=Float32BufferAttribute>(geometry: BufferGeometry, attribute: string, itemSize: number, array: number[], cls?: Class<T>) {
const attr = geometry.getAttribute(attribute) as T const attr = geometry.getAttribute(attribute) as T
const count = array.length / itemSize const count = array.length / itemSize
if (attr && attr.count === count) { if (attr && attr.count === count) {
return attr return attr
} }


function updateIndices(geometry: BufferGeometry, indices: any[]) {
function updateIndices(geometry: BufferGeometry, indices: number[]) {
const index = geometry.index const index = geometry.index
if (index && index.count === indices.length) { if (index && index.count === indices.length) {
index.set(indices) index.set(indices)


generate(g?: IGeometry, parameters: Partial<Tp> = {}): IGeometry|BufferGeometry2 { generate(g?: IGeometry, parameters: Partial<Tp> = {}): IGeometry|BufferGeometry2 {
const geometry: IGeometry = g ?? new BufferGeometry2() const geometry: IGeometry = g ?? new BufferGeometry2()
if (!geometry.userData.generationParams) geometry.userData.generationParams = {type: this.type}
geometry.userData.generationParams.type = this.type
if ((parameters as any).type) {
if ((parameters as any).type && (parameters as any).type !== this.type) {
console.error('Cannot change type of generated geometry here, use the plugin instead') console.error('Cannot change type of generated geometry here, use the plugin instead')
return geometry return geometry
} }
if (!geometry.userData.generationParams) geometry.userData.generationParams = {type: this.type}
geometry.userData.generationParams.type = this.type
const params = { const params = {
...this.defaultParams, ...this.defaultParams,
...geometry.userData.generationParams, ...geometry.userData.generationParams,
...parameters, ...parameters,
type: this.type,
} as Tp } as Tp


const {indices, vertices, normals, uvs, groups} = this._generateData(params) const {indices, vertices, normals, uvs, groups} = this._generateData(params)

+ 6
- 1
plugins/geometry-generator/src/primitives/BoxGeometryGenerator.ts Просмотреть файл



export class BoxGeometryGenerator extends AGeometryGenerator<BoxGeometryGeneratorParams> { export class BoxGeometryGenerator extends AGeometryGenerator<BoxGeometryGeneratorParams> {


defaultParams = {
constructor(type = 'box', defaultParams?: BoxGeometryGeneratorParams) {
super(type)
if (defaultParams) Object.assign(this.defaultParams, defaultParams)
}

defaultParams: BoxGeometryGeneratorParams = {
width: 1, width: 1,
height: 1, height: 1,
depth: 1, depth: 1,

+ 6
- 1
plugins/geometry-generator/src/primitives/CircleGeometryGenerator.ts Просмотреть файл



export class CircleGeometryGenerator extends AGeometryGenerator<CircleGeometryGeneratorParams> { export class CircleGeometryGenerator extends AGeometryGenerator<CircleGeometryGeneratorParams> {


defaultParams = {
constructor(type = 'circle', defaultParams?: CircleGeometryGeneratorParams) {
super(type)
if (defaultParams) Object.assign(this.defaultParams, defaultParams)
}

defaultParams: CircleGeometryGeneratorParams = {
radius: 1, radius: 1,
segments: 32, segments: 32,
thetaStart: 0, thetaStart: 0,

+ 6
- 1
plugins/geometry-generator/src/primitives/CylinderGeometryGenerator.ts Просмотреть файл



export class CylinderGeometryGenerator extends AGeometryGenerator<CylinderGeometryGeneratorParams> { export class CylinderGeometryGenerator extends AGeometryGenerator<CylinderGeometryGeneratorParams> {


defaultParams = {
constructor(type = 'cylinder', defaultParams?: CylinderGeometryGeneratorParams) {
super(type)
if (defaultParams) Object.assign(this.defaultParams, defaultParams)
}

defaultParams: CylinderGeometryGeneratorParams = {
radiusTop: 1, radiusTop: 1,
radiusBottom: 1, radiusBottom: 1,
height: 1, height: 1,

+ 6
- 1
plugins/geometry-generator/src/primitives/PlaneGeometryGenerator.ts Просмотреть файл



export class PlaneGeometryGenerator extends AGeometryGenerator<PlaneGeometryGeneratorParams> { export class PlaneGeometryGenerator extends AGeometryGenerator<PlaneGeometryGeneratorParams> {


defaultParams = {
constructor(type = 'plane', defaultParams?: PlaneGeometryGeneratorParams) {
super(type)
if (defaultParams) Object.assign(this.defaultParams, defaultParams)
}

defaultParams: PlaneGeometryGeneratorParams = {
width: 1, width: 1,
height: 1, height: 1,
widthSegments: 2, widthSegments: 2,

+ 6
- 1
plugins/geometry-generator/src/primitives/SphereGeometryGenerator.ts Просмотреть файл



export class SphereGeometryGenerator extends AGeometryGenerator<SphereGeometryGeneratorParams> { export class SphereGeometryGenerator extends AGeometryGenerator<SphereGeometryGeneratorParams> {


defaultParams = {
constructor(type = 'sphere', defaultParams?: SphereGeometryGeneratorParams) {
super(type)
if (defaultParams) Object.assign(this.defaultParams, defaultParams)
}

defaultParams: SphereGeometryGeneratorParams = {
radius: 1, radius: 1,
widthSegments: 32, widthSegments: 32,
heightSegments: 16, heightSegments: 16,

+ 6
- 1
plugins/geometry-generator/src/primitives/TorusGeometryGenerator.ts Просмотреть файл



export class TorusGeometryGenerator extends AGeometryGenerator<TorusGeometryGeneratorParams> { export class TorusGeometryGenerator extends AGeometryGenerator<TorusGeometryGeneratorParams> {


defaultParams = {
constructor(type = 'torus', defaultParams?: TorusGeometryGeneratorParams) {
super(type)
if (defaultParams) Object.assign(this.defaultParams, defaultParams)
}

defaultParams: TorusGeometryGeneratorParams = {
radius: 1, radius: 1,
tube: 0.4, tube: 0.4,
radialSegments: 12, radialSegments: 12,

Загрузка…
Отмена
Сохранить