Skip to content

Commit

Permalink
fixed bug when instantiating geomtry
Browse files Browse the repository at this point in the history
  • Loading branch information
csotomayorarch committed May 10, 2024
1 parent e4e49f2 commit 14498db
Show file tree
Hide file tree
Showing 2 changed files with 232 additions and 91 deletions.
13 changes: 3 additions & 10 deletions src/elements/CurtainWalls/SimpleCurtainWall/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,11 @@
model.ifcAPI.SetWasmPath("https://unpkg.com/[email protected]/", true);
await model.init();

const curtainWallType = new CLAY.SimpleCurtainWallType(model);

// curtainWallType.height = 5;

// curtainWallType.numberOfColumns = 3;
// curtainWallType.numberOfRows = 3;

const curtainWallType = new CLAY.SimpleCurtainWallType(model, 5, 5);

curtainWallType.height = 5
curtainWallType.startPoint.x = -10;
curtainWallType.startPoint.y = 0;

curtainWallType.endPoint.x = 0;
curtainWallType.endPoint.y = 10;

Expand All @@ -113,8 +108,6 @@

const gui = new dat.GUI();



gui
.add(curtainWallType.startPoint, "x")
.name("Start X")
Expand Down
310 changes: 229 additions & 81 deletions src/elements/CurtainWalls/SimpleCurtainWall/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ export class SimpleCurtainWallType extends StaticElementType<SimpleCurtainWall>
return vector;
}

constructor(model: Model) {
constructor(model: Model, numberOfColumns?: number, numberOfRows?: number) {
super(model);

if (numberOfColumns)
this.numberOfColumns = numberOfColumns;

if (numberOfRows)
this.numberOfRows = numberOfRows;

const componentAttributes = this.instantiateComponents(model);

Expand All @@ -81,6 +87,7 @@ export class SimpleCurtainWallType extends StaticElementType<SimpleCurtainWall>
null,
IFC.IfcCurtainWallTypeEnum.NOTDEFINED
);

this.updateComponentGeometries();
this.model.set(this.attributes);
}
Expand All @@ -91,7 +98,7 @@ export class SimpleCurtainWallType extends StaticElementType<SimpleCurtainWall>
}

instantiateComponents(model: Model = this.model) {

console.log('intantiating...')
for (let currentColumn = 0; currentColumn < this.numberOfColumns; currentColumn++) {

const bottomMember = new SimpleMemberType(model).addInstance();
Expand Down Expand Up @@ -160,90 +167,231 @@ export class SimpleCurtainWallType extends StaticElementType<SimpleCurtainWall>
return components.map((component) => component.body.attributes);
}

updateComponentGeometries(model: Model = this.model) {
const memberWidth = new SimpleMemberType(model).addInstance().width;
const plateWidth = this.length / this.numberOfColumns - memberWidth;
const plateHeight = (this.height - (this.numberOfRows + 1) * memberWidth) / this.numberOfRows;
const deltaX = (this.endPoint.x - this.startPoint.x) / this.numberOfColumns;
const deltaY = (this.endPoint.y - this.startPoint.y) / this.numberOfColumns;
const rotationY = Math.atan2(this.endPoint.x - this.startPoint.x, this.endPoint.y - this.startPoint.y);
// updateComponentGeometries(model: Model = this.model) {
// const memberWidth = new SimpleMemberType(model).addInstance().width;
// const plateWidth = this.length / this.numberOfColumns - memberWidth;
// const plateHeight = (this.height - (this.numberOfRows + 1) * memberWidth) / this.numberOfRows;
// const deltaX = (this.endPoint.x - this.startPoint.x) / this.numberOfColumns;
// const deltaY = (this.endPoint.y - this.startPoint.y) / this.numberOfColumns;
// const rotationY = Math.atan2(this.endPoint.x - this.startPoint.x, this.endPoint.y - this.startPoint.y);

// for (let currentColumn = 0; currentColumn < this.numberOfColumns; currentColumn++) {
// const posX = this.startPoint.x + currentColumn * deltaX;
// const posY = this.startPoint.y + currentColumn * deltaY;

// const bottomMember = this.bottomMembers[currentColumn];
// bottomMember.body.profile.dimension.x = this.frameWidth;
// bottomMember.body.depth = this.length / this.numberOfColumns;
// bottomMember.body.position.set(posX, posY, memberWidth / 2);
// bottomMember.body.rotation.set(Math.PI / -2, rotationY, 0);
// bottomMember.body.profile.update();
// bottomMember.body.update();

// for (let currentRow = 0; currentRow < this.numberOfRows; currentRow++) {
// const nonInitialVerticalRowLocation = memberWidth + currentRow * (plateHeight + memberWidth);

// if (currentColumn == 0) {
// const sideAMember = this.sideAMembers[currentRow];
// console.log(currentRow)
// console.log(this.sideAMembers)
// console.log('here!!!!!!!!!!!!!!!!!!!')
// sideAMember.body.profile.dimension.x = this.frameWidth;
// sideAMember.body.profile.position.y = memberWidth/2
// sideAMember.body.depth = plateHeight;
// sideAMember.body.position.set(this.startPoint.x, this.startPoint.y, currentRow > 0 ? nonInitialVerticalRowLocation : memberWidth);
// sideAMember.body.rotation.set(0, 0, -rotationY);
// sideAMember.body.profile.update();
// sideAMember.body.update();
// }

// if (currentColumn == this.numberOfColumns - 1) {
// const sideBMember = this.sideBMembers[currentRow];
// sideBMember.body.profile.dimension.x = this.frameWidth;
// sideBMember.body.profile.position.y = -1 * (memberWidth/2)
// sideBMember.body.depth = plateHeight;
// sideBMember.body.position.set(this.endPoint.x, this.endPoint.y, currentRow > 0 ? nonInitialVerticalRowLocation : memberWidth);
// sideBMember.body.rotation.set(0, 0, -rotationY);
// sideBMember.body.profile.update();
// sideBMember.body.update();
// }

// if (currentRow > 0) {
// const middleHorizontalMember = this.middleHorizontalMembers[currentColumn * (this.numberOfRows - 1) + (currentRow - 1)];
// middleHorizontalMember.body.profile.dimension.x = this.frameWidth;
// middleHorizontalMember.body.depth = this.length / this.numberOfColumns;
// middleHorizontalMember.body.position.set(posX, posY, nonInitialVerticalRowLocation - memberWidth / 2);
// middleHorizontalMember.body.rotation.set(Math.PI / -2, rotationY, 0);
// middleHorizontalMember.body.profile.update();
// middleHorizontalMember.body.update();
// }

// if (currentColumn > 0 && currentRow < this.numberOfRows) {
// const middleVerticalMember = this.middleVerticalMembers[(currentColumn - 1) * this.numberOfRows + currentRow];
// middleVerticalMember.body.profile.dimension.x = this.frameWidth;
// middleVerticalMember.body.depth = plateHeight;
// middleVerticalMember.body.position.set(posX, posY, currentRow > 0 ? nonInitialVerticalRowLocation : memberWidth);
// middleVerticalMember.body.rotation.set(0, 0, -rotationY);
// middleVerticalMember.body.profile.update();
// middleVerticalMember.body.update();
// }

// const plate = this.plates[currentColumn * this.numberOfRows + currentRow];
// plate.body.profile.dimension.y = plateWidth;
// plate.body.depth = plateHeight;
// plate.body.position.set(posX + deltaX / 2, posY + deltaY / 2, currentRow > 0 ? nonInitialVerticalRowLocation : memberWidth);
// plate.body.rotation.z = -rotationY;
// plate.body.profile.update();
// plate.body.update();
// }

// const topMember = this.topMembers[currentColumn];
// topMember.body.profile.dimension.x = this.frameWidth;
// topMember.body.depth = this.length / this.numberOfColumns;
// topMember.body.position.set(posX, posY, this.height - memberWidth / 2);
// topMember.body.rotation.set(Math.PI / -2, rotationY, 0);
// topMember.body.profile.update();
// topMember.body.update();
// }
// }

updateComponentGeometries(model: Model = this.model) {

const memberWidth = new SimpleMemberType(model).addInstance().width;
const plateWidth = this.length/this.numberOfColumns - memberWidth;
const plateHeight = (this.height - (this.numberOfRows + 1) * memberWidth) / this.numberOfRows;

for (let currentColumn = 0; currentColumn < this.numberOfColumns; currentColumn++) {

const bottomMember = this.bottomMembers[currentColumn];
bottomMember.body.profile.dimension.x = this.frameWidth;
bottomMember.body.depth = this.length / this.numberOfColumns;
bottomMember.body.position.x = this.startPoint.x+ (currentColumn/this.numberOfColumns) * (this.endPoint.x- this.startPoint.x);
bottomMember.body.position.y = this.startPoint.y+ (currentColumn/this.numberOfColumns) * (this.endPoint.y- this.startPoint.y);
bottomMember.body.position.z = memberWidth / 2;
bottomMember.body.rotation.x = Math.PI / -2;
bottomMember.body.rotation.y = Math.atan2(this.endPoint.x -this.startPoint.x, this.endPoint.y - this.startPoint.y);

if (currentColumn == this.numberOfColumns - 1) {
bottomMember.body.depth = this.length / this.numberOfColumns;
}

for (let currentColumn = 0; currentColumn < this.numberOfColumns; currentColumn++) {
const posX = this.startPoint.x + currentColumn * deltaX;
const posY = this.startPoint.y + currentColumn * deltaY;

const bottomMember = this.bottomMembers[currentColumn];
bottomMember.body.profile.dimension.x = this.frameWidth;
bottomMember.body.depth = this.length / this.numberOfColumns;
bottomMember.body.position.set(posX, posY, memberWidth / 2);
bottomMember.body.rotation.set(Math.PI / -2, rotationY, 0);
bottomMember.body.profile.update();
bottomMember.body.update();

for (let currentRow = 0; currentRow < this.numberOfRows; currentRow++) {
const nonInitialVerticalRowLocation = memberWidth + currentRow * (plateHeight + memberWidth);

if (currentColumn == 0) {
const sideAMember = this.sideAMembers[currentRow];
sideAMember.body.profile.dimension.x = this.frameWidth;
sideAMember.body.profile.position.y = memberWidth/2
sideAMember.body.depth = plateHeight;
sideAMember.body.position.set(this.startPoint.x, this.startPoint.y, currentRow > 0 ? nonInitialVerticalRowLocation : memberWidth);
sideAMember.body.rotation.set(0, 0, -rotationY);
sideAMember.body.profile.update();
sideAMember.body.update();
}

if (currentColumn == this.numberOfColumns - 1) {
const sideBMember = this.sideBMembers[currentRow];
sideBMember.body.profile.dimension.x = this.frameWidth;
sideBMember.body.profile.position.y = -1 * (memberWidth/2)
sideBMember.body.depth = plateHeight;
sideBMember.body.position.set(this.endPoint.x, this.endPoint.y, currentRow > 0 ? nonInitialVerticalRowLocation : memberWidth);
sideBMember.body.rotation.set(0, 0, -rotationY);
sideBMember.body.profile.update();
sideBMember.body.update();
}

if (currentRow > 0) {
const middleHorizontalMember = this.middleHorizontalMembers[currentColumn * (this.numberOfRows - 1) + (currentRow - 1)];
middleHorizontalMember.body.profile.dimension.x = this.frameWidth;
middleHorizontalMember.body.depth = this.length / this.numberOfColumns;
middleHorizontalMember.body.position.set(posX, posY, nonInitialVerticalRowLocation - memberWidth / 2);
middleHorizontalMember.body.rotation.set(Math.PI / -2, rotationY, 0);
middleHorizontalMember.body.profile.update();
middleHorizontalMember.body.update();
}

if (currentColumn > 0 && currentRow < this.numberOfRows) {
const middleVerticalMember = this.middleVerticalMembers[(currentColumn - 1) * this.numberOfRows + currentRow];
middleVerticalMember.body.profile.dimension.x = this.frameWidth;
middleVerticalMember.body.depth = plateHeight;
middleVerticalMember.body.position.set(posX, posY, currentRow > 0 ? nonInitialVerticalRowLocation : memberWidth);
middleVerticalMember.body.rotation.set(0, 0, -rotationY);
middleVerticalMember.body.profile.update();
middleVerticalMember.body.update();
}

const plate = this.plates[currentColumn * this.numberOfRows + currentRow];
plate.body.profile.dimension.y = plateWidth;
plate.body.depth = plateHeight;
plate.body.position.set(posX + deltaX / 2, posY + deltaY / 2, currentRow > 0 ? nonInitialVerticalRowLocation : memberWidth);
plate.body.rotation.z = -rotationY;
plate.body.profile.update();
plate.body.update();
bottomMember.body.profile.update();
bottomMember.body.update();

for (let currentRow = 0; currentRow < this.numberOfRows; currentRow++) {

const nonInitialVerticalRowLocation = memberWidth + currentRow * (plateHeight + memberWidth);

if (currentColumn == 0) {

const sideAMember = this.sideAMembers[currentRow]
sideAMember.body.profile.dimension.x = this.frameWidth;
sideAMember.body.profile.position.y = memberWidth/2
sideAMember.body.depth = plateHeight;
sideAMember.body.position.x = this.startPoint.x;
sideAMember.body.position.y = this.startPoint.y;
sideAMember.body.position.z = memberWidth;
sideAMember.body.rotation.z = -1 * Math.atan2(this.endPoint.x -this.startPoint.x, this.endPoint.y - this.startPoint.y);

if (currentRow > 0) {
sideAMember.body.position.z = nonInitialVerticalRowLocation;
}

sideAMember.body.profile.update();
sideAMember.body.update();
}

if (currentRow > 0) {

const middleHorizontalMember = this.middleHorizontalMembers[currentColumn * (this.numberOfRows - 1) + (currentRow - 1)]
middleHorizontalMember.body.profile.dimension.x = this.frameWidth;
middleHorizontalMember.body.depth = this.length / this.numberOfColumns;
middleHorizontalMember.body.position.x = this.startPoint.x+ (currentColumn/this.numberOfColumns) * (this.endPoint.x- this.startPoint.x);
middleHorizontalMember.body.position.y = this.startPoint.y+ (currentColumn/this.numberOfColumns) * (this.endPoint.y- this.startPoint.y);
middleHorizontalMember.body.position.z = nonInitialVerticalRowLocation - memberWidth / 2;
middleHorizontalMember.body.rotation.x = Math.PI / -2;
middleHorizontalMember.body.rotation.y = Math.atan2(this.endPoint.x -this.startPoint.x, this.endPoint.y - this.startPoint.y);

middleHorizontalMember.body.profile.update();
middleHorizontalMember.body.update();
}

if (currentColumn > 0) {

const middleVerticalMember = this.middleVerticalMembers[(currentColumn - 1) * this.numberOfRows + currentRow]
middleVerticalMember.body.profile.dimension.x = this.frameWidth;
middleVerticalMember.body.depth = plateHeight;
middleVerticalMember.body.position.x = this.startPoint.x+ (currentColumn/this.numberOfColumns) * (this.endPoint.x- this.startPoint.x);
middleVerticalMember.body.position.y = this.startPoint.y+ (currentColumn/this.numberOfColumns) * (this.endPoint.y- this.startPoint.y);
middleVerticalMember.body.position.z = memberWidth;
middleVerticalMember.body.rotation.z = -1 * Math.atan2(this.endPoint.x -this.startPoint.x, this.endPoint.y - this.startPoint.y);

const topMember = this.topMembers[currentColumn];
topMember.body.profile.dimension.x = this.frameWidth;
topMember.body.depth = this.length / this.numberOfColumns;
topMember.body.position.set(posX, posY, this.height - memberWidth / 2);
topMember.body.rotation.set(Math.PI / -2, rotationY, 0);
topMember.body.profile.update();
topMember.body.update();
if (currentRow > 0) {
middleVerticalMember.body.position.z = nonInitialVerticalRowLocation;
}
middleVerticalMember.body.profile.update();
middleVerticalMember.body.update();
}


if (currentColumn == this.numberOfColumns - 1) {

const sideBMember = this.sideBMembers[currentRow]
sideBMember.body.profile.position.y = -1 * (memberWidth/2)
sideBMember.body.profile.dimension.x = this.frameWidth;
sideBMember.body.depth = plateHeight;
sideBMember.body.position.x = this.endPoint.x;
sideBMember.body.position.y = this.endPoint.y
sideBMember.body.position.z = memberWidth;
sideBMember.body.rotation.z = -1 * Math.atan2(this.endPoint.x -this.startPoint.x, this.endPoint.y - this.startPoint.y);

if (currentRow > 0) {
sideBMember.body.position.z = nonInitialVerticalRowLocation;
}

sideBMember.body.profile.update();
sideBMember.body.update();
}
}

const plate = this.plates[currentColumn * this.numberOfRows + currentRow];
plate.body.profile.dimension.y = plateWidth;
plate.body.depth = plateHeight;
plate.body.position.z = memberWidth;
plate.body.position.x = this.startPoint.x+ (((this.endPoint.x - this.startPoint.x)/this.numberOfColumns) /2) + ((currentColumn/this.numberOfColumns) * (this.endPoint.x- this.startPoint.x)) ;
plate.body.position.y = this.startPoint.y+ (((this.endPoint.y - this.startPoint.y)/this.numberOfColumns) /2) + ((currentColumn/this.numberOfColumns) * (this.endPoint.y- this.startPoint.y)) ;
plate.body.rotation.z = -1 * Math.atan2(this.endPoint.x -this.startPoint.x, this.endPoint.y - this.startPoint.y);

if (currentRow > 0) {
plate.body.position.z = nonInitialVerticalRowLocation;
}

if (currentColumn == 0 || currentColumn == this.numberOfColumns - 1)
{
plate.body.profile.dimension.y = plateWidth - memberWidth/2
plate.body.profile.position.y = memberWidth/4
}

if (currentColumn == this.numberOfColumns - 1) {
plate.body.profile.position.y = -memberWidth/4
}

plate.body.profile.update();
plate.body.update();
}

const topMember = this.topMembers[currentColumn]
topMember.body.profile.dimension.x = this.frameWidth;
topMember.body.depth = this.length / this.numberOfColumns;
topMember.body.position.x = this.startPoint.x+ (currentColumn/this.numberOfColumns) * (this.endPoint.x- this.startPoint.x);
topMember.body.position.y = this.startPoint.y+ (currentColumn/this.numberOfColumns) * (this.endPoint.y- this.startPoint.y);
topMember.body.position.z = this.height - memberWidth / 2;
topMember.body.rotation.x = Math.PI / -2;
topMember.body.rotation.y = Math.atan2(this.endPoint.x -this.startPoint.x, this.endPoint.y - this.startPoint.y);

topMember.body.profile.update();
topMember.body.update();
}
}
protected createElement() {
return new SimpleCurtainWall(this.model, this);
}
Expand Down

0 comments on commit 14498db

Please sign in to comment.