Skip to content
Snippets Groups Projects
Commit b309c545 authored by giagitom's avatar giagitom
Browse files

- Fixed dashes spacing

- Added changelog entry
parent 257370ad
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,8 @@ Note that since we don't clearly distinguish between a public and private interf
## [Unreleased]
- Enable odd dash count (1,3,5)
## [v3.33.0] - 2023-04-02
- Handle resizes of viewer element even when window remains the same size
......
......@@ -45,24 +45,21 @@ export namespace CylindersBuilder {
const addFixedCountDashes = (start: Vec3, end: Vec3, segmentCount: number, radiusScale: number, topCap: boolean, bottomCap: boolean, stubCap: boolean, group: number) => {
const d = Vec3.distance(start, end);
const isOdd = segmentCount % 2 !== 0;
segmentCount++;
const s = Math.floor(segmentCount / 2);
const step = 1 / segmentCount;
const offset = step / 2;
const s = Math.floor((segmentCount + 1) / 2);
const step = d / (segmentCount + 0.5);
Vec3.sub(tmpDir, end, start);
Vec3.setMagnitude(tmpDir, Vec3.sub(tmpDir, end, start), step);
Vec3.copy(tmpVecA, start);
for (let j = 0; j < s; ++j) {
const f = step * (j * 2 + 1) + offset;
Vec3.setMagnitude(tmpDir, tmpDir, d * f);
Vec3.add(tmpVecA, start, tmpDir);
Vec3.add(tmpVecA, tmpVecA, tmpDir);
if (isOdd && j === s - 1) {
Vec3.copy(tmpVecB, end);
if (!stubCap) bottomCap = false;
} else {
Vec3.setMagnitude(tmpDir, tmpDir, d * (step * ((j + 1) * 2) + offset));
Vec3.add(tmpVecB, start, tmpDir);
Vec3.add(tmpVecB, tmpVecA, tmpDir);
}
add(tmpVecA[0], tmpVecA[1], tmpVecA[2], tmpVecB[0], tmpVecB[1], tmpVecB[2], radiusScale, topCap, bottomCap, group);
Vec3.add(tmpVecA, tmpVecA, tmpDir);
}
};
......
......@@ -52,23 +52,20 @@ export namespace LinesBuilder {
const addFixedCountDashes = (start: Vec3, end: Vec3, segmentCount: number, group: number) => {
const d = Vec3.distance(start, end);
const isOdd = segmentCount % 2 !== 0;
segmentCount++;
const s = Math.floor(segmentCount / 2);
const step = 1 / segmentCount;
const offset = step / 2;
const s = Math.floor((segmentCount + 1) / 2);
const step = d / (segmentCount + 0.5);
Vec3.sub(tmpDir, end, start);
Vec3.setMagnitude(tmpDir, Vec3.sub(tmpDir, end, start), step);
Vec3.copy(tmpVecA, start);
for (let j = 0; j < s; ++j) {
const f = step * (j * 2 + 1) + offset;
Vec3.setMagnitude(tmpDir, tmpDir, d * f);
Vec3.add(tmpVecA, start, tmpDir);
Vec3.add(tmpVecA, tmpVecA, tmpDir);
if (isOdd && j === s - 1) {
Vec3.copy(tmpVecB, end);
} else {
Vec3.setMagnitude(tmpDir, tmpDir, d * step * ((j + 1) * 2) + offset);
Vec3.add(tmpVecB, start, tmpDir);
Vec3.add(tmpVecB, tmpVecA, tmpDir);
}
add(tmpVecA[0], tmpVecA[1], tmpVecA[2], tmpVecB[0], tmpVecB[1], tmpVecB[2], group);
Vec3.add(tmpVecA, tmpVecA, tmpDir);
}
};
......
......@@ -101,28 +101,24 @@ export function addDoubleCylinder(state: MeshBuilder.State, start: Vec3, end: Ve
export function addFixedCountDashedCylinder(state: MeshBuilder.State, start: Vec3, end: Vec3, lengthScale: number, segmentCount: number, stubCap: boolean, props: BasicCylinderProps) {
const d = Vec3.distance(start, end) * lengthScale;
const isOdd = segmentCount % 2 !== 0;
segmentCount++;
const s = Math.floor(segmentCount / 2);
const step = 1 / segmentCount;
const offset = step / 2;
const s = Math.floor((segmentCount + 1) / 2);
let step = d / (segmentCount + 0.5);
let cylinder = getCylinder(props);
Vec3.sub(tmpCylinderDir, end, start);
Vec3.setMagnitude(tmpCylinderDir, Vec3.sub(tmpCylinderDir, end, start), step);
Vec3.copy(tmpCylinderStart, start);
for (let j = 0; j < s; ++j) {
const f = step * (j * 2 + 1) + offset;
let len = d * step;
Vec3.setMagnitude(tmpCylinderDir, tmpCylinderDir, d * f);
Vec3.add(tmpCylinderStart, start, tmpCylinderDir);
Vec3.add(tmpCylinderStart, tmpCylinderStart, tmpCylinderDir);
if (isOdd && j === s - 1) {
if (!stubCap && props.topCap) {
props.topCap = false;
cylinder = getCylinder(props);
}
len /= 2;
step /= 2;
}
setCylinderMat(tmpCylinderMat, tmpCylinderStart, tmpCylinderDir, len, false);
setCylinderMat(tmpCylinderMat, tmpCylinderStart, tmpCylinderDir, step, false);
MeshBuilder.addPrimitive(state, tmpCylinderMat, cylinder);
Vec3.add(tmpCylinderStart, tmpCylinderStart, tmpCylinderDir);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment