Complete transition to WebGPU
This commit is contained in:
parent
4dadaf470c
commit
ce20daeee2
3 changed files with 11 additions and 32 deletions
|
@ -75,7 +75,7 @@ const fragmentShader = /*#__PURE__*/ Fn(() => {
|
||||||
.and(positionWorld.y.greaterThanEqual(bounds.z))
|
.and(positionWorld.y.greaterThanEqual(bounds.z))
|
||||||
.and(positionWorld.y.lessThanEqual(bounds.w)),
|
.and(positionWorld.y.lessThanEqual(bounds.w)),
|
||||||
() => {
|
() => {
|
||||||
let uv = positionWorld.xy
|
const uv = positionWorld.xy
|
||||||
.sub(bounds.xz)
|
.sub(bounds.xz)
|
||||||
.div(bounds.yw.sub(bounds.xz))
|
.div(bounds.yw.sub(bounds.xz))
|
||||||
.toVar();
|
.toVar();
|
||||||
|
|
|
@ -8,7 +8,6 @@ import {
|
||||||
LineBasicMaterial,
|
LineBasicMaterial,
|
||||||
LineSegments,
|
LineSegments,
|
||||||
Mesh,
|
Mesh,
|
||||||
MeshStandardMaterial,
|
|
||||||
Object3DEventMap,
|
Object3DEventMap,
|
||||||
PerspectiveCamera,
|
PerspectiveCamera,
|
||||||
Plane,
|
Plane,
|
||||||
|
@ -26,7 +25,7 @@ import {
|
||||||
MeshStandardNodeMaterial,
|
MeshStandardNodeMaterial,
|
||||||
WebGPURenderer,
|
WebGPURenderer,
|
||||||
} from "three/webgpu";
|
} from "three/webgpu";
|
||||||
import { Fn, uniform, vec4 } from "three/tsl";
|
import { vec4 } from "three/tsl";
|
||||||
|
|
||||||
export enum Orientation {
|
export enum Orientation {
|
||||||
X = "X",
|
X = "X",
|
||||||
|
@ -648,36 +647,19 @@ function generateCapMeshes(
|
||||||
// Intersection surface can be a multipolygon consisting of disconnected polygons
|
// Intersection surface can be a multipolygon consisting of disconnected polygons
|
||||||
const polygons: Vector3[][] = buildPolygons(edges);
|
const polygons: Vector3[][] = buildPolygons(edges);
|
||||||
|
|
||||||
const offset =
|
|
||||||
orientation === Orientation.NX ||
|
|
||||||
orientation === Orientation.NY ||
|
|
||||||
orientation === Orientation.NZ
|
|
||||||
? 1
|
|
||||||
: -1;
|
|
||||||
|
|
||||||
const color =
|
const color =
|
||||||
mesh.material instanceof MeshStandardNodeMaterial
|
mesh.material instanceof MeshStandardNodeMaterial
|
||||||
? mesh.material.color
|
? mesh.material.color
|
||||||
: new Color(1, 1, 1);
|
: new Color(0.1, 0.1, 0.1);
|
||||||
|
|
||||||
const material = new MeshStandardNodeMaterial({
|
const material = new MeshStandardNodeMaterial({
|
||||||
color,
|
|
||||||
side: DoubleSide,
|
side: DoubleSide,
|
||||||
metalness: 0.1,
|
|
||||||
roughness: 0.5,
|
|
||||||
flatShading: true,
|
flatShading: true,
|
||||||
polygonOffset: true,
|
|
||||||
polygonOffsetFactor: offset,
|
|
||||||
polygonOffsetUnits: offset,
|
|
||||||
wireframe: scene.userData.wireframe,
|
wireframe: scene.userData.wireframe,
|
||||||
alphaToCoverage: true,
|
alphaToCoverage: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const tColor = uniform(new Color(color));
|
material.colorNode = vec4(color.r, color.g, color.b, 1.0);
|
||||||
const fragmentShader = Fn(() => {
|
|
||||||
return vec4(tColor.r, tColor.g, tColor.b, 1.0);
|
|
||||||
});
|
|
||||||
material.fragmentNode = fragmentShader();
|
|
||||||
|
|
||||||
polygons.forEach((polygon) => {
|
polygons.forEach((polygon) => {
|
||||||
const geometry = triangulatePolygon(polygon, plane);
|
const geometry = triangulatePolygon(polygon, plane);
|
||||||
|
@ -687,7 +669,7 @@ function generateCapMeshes(
|
||||||
capMesh.name = mesh.name;
|
capMesh.name = mesh.name;
|
||||||
|
|
||||||
// Offset mesh to avoid flickering
|
// Offset mesh to avoid flickering
|
||||||
const normal = plane.normal.clone().multiplyScalar(offset);
|
const normal = plane.normal.clone().multiplyScalar(10);
|
||||||
|
|
||||||
const positionAttr = capMesh.geometry.attributes.position;
|
const positionAttr = capMesh.geometry.attributes.position;
|
||||||
for (let i = 0; i < positionAttr.count; i++) {
|
for (let i = 0; i < positionAttr.count; i++) {
|
||||||
|
@ -698,7 +680,7 @@ function generateCapMeshes(
|
||||||
}
|
}
|
||||||
positionAttr.needsUpdate = true;
|
positionAttr.needsUpdate = true;
|
||||||
|
|
||||||
if (capMesh) {
|
if (capMesh && geometry.index && geometry.index.count > 0) {
|
||||||
capMeshGroup.add(capMesh);
|
capMeshGroup.add(capMesh);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { fetchVertices, fetchTriangleIndices, transform } from "./utils";
|
||||||
import { TRIANGLE_INDICES_URL, VERTICES_URL } from "../config";
|
import { TRIANGLE_INDICES_URL, VERTICES_URL } from "../config";
|
||||||
import { topoNodeMaterial } from "../ShaderMaterial";
|
import { topoNodeMaterial } from "../ShaderMaterial";
|
||||||
import { MeshStandardNodeMaterial } from "three/webgpu";
|
import { MeshStandardNodeMaterial } from "three/webgpu";
|
||||||
import { Fn, uniform, vec3, vec4 } from "three/tsl";
|
import { vec4 } from "three/tsl";
|
||||||
|
|
||||||
interface MappedFeature {
|
interface MappedFeature {
|
||||||
featuregeom_id: number;
|
featuregeom_id: number;
|
||||||
|
@ -36,7 +36,7 @@ export async function buildMeshes(mappedFeatures: MappedFeature[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function buildMesh(layerData: MappedFeature) {
|
async function buildMesh(layerData: MappedFeature) {
|
||||||
const color = `#${layerData.preview.legend_color}`;
|
const colorHex = `#${layerData.preview.legend_color}`;
|
||||||
const name = layerData.preview.legend_text;
|
const name = layerData.preview.legend_text;
|
||||||
const geomId = layerData.featuregeom_id.toString();
|
const geomId = layerData.featuregeom_id.toString();
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ async function buildMesh(layerData: MappedFeature) {
|
||||||
geometry.computeVertexNormals();
|
geometry.computeVertexNormals();
|
||||||
|
|
||||||
const material = new MeshStandardNodeMaterial({
|
const material = new MeshStandardNodeMaterial({
|
||||||
color: color,
|
color: colorHex,
|
||||||
metalness: 0.1,
|
metalness: 0.1,
|
||||||
roughness: 0.5,
|
roughness: 0.5,
|
||||||
flatShading: true,
|
flatShading: true,
|
||||||
|
@ -73,11 +73,8 @@ async function buildMesh(layerData: MappedFeature) {
|
||||||
alphaToCoverage: true,
|
alphaToCoverage: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const tColor = uniform(new Color(color));
|
const color = new Color(colorHex);
|
||||||
const fragmentShader = Fn(() => {
|
material.colorNode = vec4(color.r, color.g, color.b, 1.0);
|
||||||
return vec4(tColor.r, tColor.g, tColor.b, 1.0);
|
|
||||||
});
|
|
||||||
material.colorNode = fragmentShader();
|
|
||||||
|
|
||||||
const mesh = new Mesh(
|
const mesh = new Mesh(
|
||||||
geometry,
|
geometry,
|
||||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue