Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GreasedLine changes #14943

Merged
merged 25 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2268a43
world vs finalWorld fix
RolandCsibrei Oct 26, 2023
63c69f6
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js
RolandCsibrei Oct 26, 2023
bcc1bce
formatting
RolandCsibrei Oct 26, 2023
1433f49
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js
RolandCsibrei Nov 12, 2023
4fd1ee1
merge from upstream
RolandCsibrei Jan 1, 2024
9e1cbf1
get/set uvs
RolandCsibrei Jan 1, 2024
2bde014
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js
RolandCsibrei Jan 1, 2024
7acb184
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js
RolandCsibrei Apr 2, 2024
1c8aecc
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js
RolandCsibrei Apr 3, 2024
bde8e1d
Added GreasedLineRibbonAutoDirectionMode.AUTO_DIRECTION_FACE_TO, fixe…
RolandCsibrei Apr 3, 2024
9b5e376
Added ribbonOptions validity checking for face_to mode
RolandCsibrei Apr 3, 2024
20381b2
Added comment
RolandCsibrei Apr 3, 2024
7cf4273
formatting
RolandCsibrei Apr 3, 2024
1e4737b
Delete package-lock.json
RolandCsibrei Apr 3, 2024
1914f0b
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js
RolandCsibrei Apr 4, 2024
924ef1d
Merge branch 'master' of github.com:RolandCsibrei/Babylon.js
RolandCsibrei Apr 4, 2024
4dfd324
uvs to FloatArray fix
RolandCsibrei Apr 4, 2024
1fd11e0
FloatArray iteration for UMD fix
RolandCsibrei Apr 4, 2024
3157369
added the mistakenly deleted package-lock.json file
RolandCsibrei Apr 4, 2024
5258399
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js
RolandCsibrei Apr 4, 2024
affd559
Removed package-lock.json
RolandCsibrei Apr 4, 2024
c58fe0a
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js
RolandCsibrei Apr 8, 2024
943fb84
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js
RolandCsibrei Apr 8, 2024
65ea3cf
Added package-lock.json
RolandCsibrei Apr 8, 2024
3718ec8
package-lock.json
RolandCsibrei Apr 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/dev/core/src/Meshes/Builders/greasedLineBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ export function CreateGreasedLine(name: string, options: GreasedLineMeshBuilderO
if (instance instanceof GreasedLineRibbonMesh) {
instance.addPoints(allPoints, initialGreasedLineOptions);
} else {
// add widths
const currentWidths = instance.widths;

if (currentWidths) {
const newWidths = currentWidths.slice();
for (const w of widths) {
Expand All @@ -249,7 +249,21 @@ export function CreateGreasedLine(name: string, options: GreasedLineMeshBuilderO
} else {
instance.widths = widths;
}

instance.addPoints(allPoints);

// add UVs
if (options.uvs) {
const currentUVs = instance.uvs;
if (currentUVs) {
const newUVs = new Float32Array(currentUVs.length + options.uvs.length);
newUVs.set(currentUVs, 0);
newUVs.set(options.uvs, currentUVs.length);
instance.uvs = newUVs;
} else {
instance.uvs = options.uvs;
}
}
}
}

Expand Down
26 changes: 22 additions & 4 deletions packages/dev/core/src/Meshes/GreasedLine/greasedLineBaseMesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ export enum GreasedLineRibbonFacesMode {
* AUTO_DIRECTIONS_FROM_FIRST_SEGMENT sets the direction (slope) of the ribbon from the direction of the first line segment. Recommended.
* AUTO_DIRECTIONS_FROM_ALL_SEGMENTS in this mode the direction (slope) will be calculated for each line segment according to the direction vector between each point of the line segments. Slow method.
* AUTO_DIRECTIONS_ENHANCED in this mode the direction (slope) will be calculated for each line segment according to the direction vector between each point of the line segments using a more sophisitcaed algorithm. Slowest method.
* AUTO_DIRECTIONS_FACE_TO in this mode the direction (slope) will be calculated for each line segment according to the direction vector between each point of the line segments and a direction (face-to) vector specified in direction. The resulting line will face to the direction of this face-to vector.
* AUTO_DIRECTIONS_NONE you have to set the direction (slope) manually. Recommended.
*/
export enum GreasedLineRibbonAutoDirectionMode {
AUTO_DIRECTIONS_FROM_FIRST_SEGMENT = 0,
AUTO_DIRECTIONS_FROM_ALL_SEGMENTS = 1,
AUTO_DIRECTIONS_ENHANCED = 2,
AUTO_DIRECTIONS_FACE_TO = 3,
AUTO_DIRECTIONS_NONE = 99,
}

Expand Down Expand Up @@ -92,7 +94,7 @@ export interface GreasedLineMeshOptions {
*/
points: GreasedLinePoints;
/**
* Each line segmment (from point to point) can have it's width multiplier. Final width = widths[segmentIdx] * width.
* Each line segment (from point to point) can have it's width multiplier. Final width = widths[segmentIdx] * width.
* Defaults to empty array.
*/
widths?: number[];
Expand All @@ -109,7 +111,7 @@ export interface GreasedLineMeshOptions {
/**
* UVs for the mesh
*/
uvs?: number[];
uvs?: FloatArray;
/**
* If true, offsets and widths are updatable.
* Defaults to false.
Expand Down Expand Up @@ -231,14 +233,30 @@ export abstract class GreasedLineBaseMesh extends Mesh {
}

/**
*
* @returns true if the mesh was created in lazy mode
*/
public isLazy(): boolean {
return this._lazy;
}

/**
* Returns the UVs
*/
get uvs() {
return this._uvs;
}

/**
* Sets the UVs
* @param uvs the UVs
*/
set uvs(uvs: FloatArray) {
this._uvs = uvs instanceof Float32Array ? uvs : new Float32Array(uvs);
this._createVertexBuffers();
}

/**
* Returns the points offsets
* Return the points offsets
*/
get offsets() {
Expand Down Expand Up @@ -343,7 +361,7 @@ export abstract class GreasedLineBaseMesh extends Mesh {
colorPointers: this._colorPointers,
lazy: this._lazy,
updatable: this._updatable,
uvs: this._uvs instanceof Float32Array ? Array.from(this._uvs) : this._uvs,
uvs: this._uvs,
widths: this._widths,
ribbonOptions: this._options.ribbonOptions,
};
Expand Down
8 changes: 3 additions & 5 deletions packages/dev/core/src/Meshes/GreasedLine/greasedLineMesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import { Mesh } from "../mesh";
import type { Ray, TrianglePickingPredicate } from "../../Culling/ray";
import { Buffer, VertexBuffer } from "../../Buffers/buffer";
import { PickingInfo } from "../../Collisions/pickingInfo";
import type { Nullable } from "../../types";
import type { Nullable, FloatArray } from "../../types";
import type { Node } from "../../node";
import { DeepCopier } from "../../Misc/deepCopier";
import { GreasedLineTools } from "../../Misc/greasedLineTools";
import type { GreasedLineMeshOptions } from "./greasedLineBaseMesh";
import { GreasedLineBaseMesh } from "./greasedLineBaseMesh";
import type { VertexData } from "../mesh.vertexData";
import type { FloatArray } from "../../types";

Mesh._GreasedLineMeshParser = (parsedMesh: any, scene: Scene): Mesh => {
return GreasedLineMesh.Parse(parsedMesh, scene);
Expand Down Expand Up @@ -176,9 +175,8 @@ export class GreasedLineMesh extends GreasedLineBaseMesh {
nextAndCounters[nextAndCountersOffset++] = lengthArray[i >> 1] / totalLength;
}
if (this._options.uvs) {
const uvs = this._options.uvs;
for (const uv of uvs) {
uvArr[uvOffset++] = uv;
for (let i = 0; i < this._options.uvs.length; i++) {
uvArr[uvOffset++] = this._options.uvs[i];
}
} else {
for (let j = 0; j < l; j++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Scene } from "../../scene";
import { Quaternion, Vector3 } from "../../Maths/math.vector";
import { Quaternion, TmpVectors, Vector3 } from "../../Maths/math.vector";
import { Mesh } from "../mesh";
import { Buffer } from "../../Buffers/buffer";
import type { Nullable } from "../../types";
Expand Down Expand Up @@ -383,12 +383,21 @@ export class GreasedLineRibbonMesh extends GreasedLineBaseMesh {
directionPlane = GreasedLineRibbonMesh._GetDirectionFromPoints(pointVectors[0], pointVectors[1], null);
}

if (ribbonInfo.directionsAutoMode === GreasedLineRibbonAutoDirectionMode.AUTO_DIRECTIONS_FACE_TO && !(ribbonInfo.directions instanceof Vector3)) {
// eslint-disable-next-line no-throw-literal
throw "In GreasedLineRibbonAutoDirectionMode.AUTO_DIRECTIONS_FACE_TO 'GreasedLineMeshOptions.ribbonOptions.directions' must be a Vector3.";
}

TmpVectors.Vector3[1] = ribbonInfo.directions instanceof Vector3 ? ribbonInfo.directions : GreasedLineRibbonMesh.DIRECTION_XZ;
for (let i = 0; i < pointVectors.length - (directionPlane ? 0 : 1); i++) {
const p1 = pointVectors[i];
const p2 = pointVectors[i + 1];

if (directionPlane) {
direction = <Vector3>directionPlane;
} else if (ribbonInfo.directionsAutoMode === GreasedLineRibbonAutoDirectionMode.AUTO_DIRECTIONS_FACE_TO) {
p2.subtractToRef(p1, TmpVectors.Vector3[0]);
direction = Vector3.CrossToRef(TmpVectors.Vector3[0], TmpVectors.Vector3[1], TmpVectors.Vector3[2]).normalize();
} else if (ribbonInfo.directionsAutoMode === GreasedLineRibbonAutoDirectionMode.AUTO_DIRECTIONS_FROM_ALL_SEGMENTS) {
direction = GreasedLineRibbonMesh._GetDirectionFromPoints(p1, p2, direction);
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/dev/core/src/Shaders/greasedLine.vertex.fx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void main() {
#include<instancesVertex>

grlColorPointer = grl_colorPointers;
mat4 grlMatrix = viewProjection * finalWorld ;

#ifdef GREASED_LINE_CAMERA_FACING
float grlBaseWidth = grlWidth;
Expand All @@ -42,7 +43,6 @@ void main() {
vec3 grlNext = grl_nextAndCounters.xyz;
grlCounters = grl_nextAndCounters.w;

mat4 grlMatrix = viewProjection * finalWorld ;

vec3 grlPositionOffset = grl_offsets;
vec4 grlFinalPosition = grlMatrix * vec4( position + grlPositionOffset , 1.0 );
Expand Down Expand Up @@ -78,7 +78,7 @@ void main() {
gl_Position = grlFinalPosition;
#else
grlCounters = grl_counters;
vec4 grlFinalPosition = worldViewProjection * vec4( (position + grl_offsets) + grl_slopes * grl_widths , 1.0 ) ;
vec4 grlFinalPosition = grlMatrix * vec4( (position + grl_offsets) + grl_slopes * grl_widths , 1.0 ) ;
gl_Position = grlFinalPosition;
#endif
}