mirror of https://github.com/CesiumGS/cesium.git
feature id save
This commit is contained in:
parent
cd5e791b1a
commit
604dac1e03
|
|
@ -11,7 +11,6 @@ import EdgeVisibilityStageFS from "../../Shaders/Model/EdgeVisibilityStageFS.js"
|
|||
import ModelUtility from "./ModelUtility.js";
|
||||
import ModelReader from "./ModelReader.js";
|
||||
import VertexAttributeSemantic from "../VertexAttributeSemantic.js";
|
||||
import ModelComponents from "../ModelComponents.js";
|
||||
|
||||
const EdgeVisibilityPipelineStage = {
|
||||
name: "EdgeVisibilityPipelineStage",
|
||||
|
|
@ -55,13 +54,6 @@ EdgeVisibilityPipelineStage.process = function (
|
|||
const edgeTypeLocation = shaderBuilder.addAttribute("float", "a_edgeType");
|
||||
shaderBuilder.addVarying("float", "v_edgeType", "flat");
|
||||
|
||||
// Add feature ID attribute and varying for edge geometry
|
||||
const edgeFeatureIdLocation = shaderBuilder.addAttribute(
|
||||
"float",
|
||||
"a_edgeFeatureId",
|
||||
);
|
||||
shaderBuilder.addVarying("float", "v_edgeFeatureId", "flat");
|
||||
|
||||
// Add silhouette normal attribute and varying for silhouette edges
|
||||
const silhouetteNormalLocation = shaderBuilder.addAttribute(
|
||||
"vec3",
|
||||
|
|
@ -88,7 +80,6 @@ EdgeVisibilityPipelineStage.process = function (
|
|||
shaderBuilder.addFunctionLines("setDynamicVaryingsVS", [
|
||||
"#ifdef HAS_EDGE_VISIBILITY",
|
||||
" v_edgeType = a_edgeType;",
|
||||
" v_edgeFeatureId = a_edgeFeatureId;",
|
||||
" // Transform normals from model space to view space",
|
||||
" v_silhouetteNormalView = czm_normal * a_silhouetteNormal;",
|
||||
" v_faceNormalAView = czm_normal * a_faceNormalA;",
|
||||
|
|
@ -125,7 +116,6 @@ EdgeVisibilityPipelineStage.process = function (
|
|||
renderResources,
|
||||
frameState.context,
|
||||
edgeTypeLocation,
|
||||
edgeFeatureIdLocation,
|
||||
silhouetteNormalLocation,
|
||||
faceNormalALocation,
|
||||
faceNormalBLocation,
|
||||
|
|
@ -423,7 +413,6 @@ function extractVisibleEdges(primitive) {
|
|||
* @param {PrimitiveRenderResources} renderResources The render resources
|
||||
* @param {Context} context The rendering context
|
||||
* @param {number} edgeTypeLocation The shader location for edge type attribute
|
||||
* @param {number} edgeFeatureIdLocation The shader location for edge feature ID attribute
|
||||
* @param {number} silhouetteNormalLocation The shader location for silhouette normal attribute
|
||||
* @param {number} faceNormalALocation The shader location for face normal A attribute
|
||||
* @param {number} faceNormalBLocation The shader location for face normal B attribute
|
||||
|
|
@ -438,7 +427,6 @@ function createCPULineEdgeGeometry(
|
|||
renderResources,
|
||||
context,
|
||||
edgeTypeLocation,
|
||||
edgeFeatureIdLocation,
|
||||
silhouetteNormalLocation,
|
||||
faceNormalALocation,
|
||||
faceNormalBLocation,
|
||||
|
|
@ -468,7 +456,6 @@ function createCPULineEdgeGeometry(
|
|||
// Create edge-domain vertices (2 per edge)
|
||||
const edgePosArray = new Float32Array(totalVerts * 3);
|
||||
const edgeTypeArray = new Float32Array(totalVerts);
|
||||
const edgeFeatureIdArray = new Float32Array(totalVerts);
|
||||
const silhouetteNormalArray = new Float32Array(totalVerts * 3);
|
||||
const faceNormalAArray = new Float32Array(totalVerts * 3);
|
||||
const faceNormalBArray = new Float32Array(totalVerts * 3);
|
||||
|
|
@ -476,46 +463,6 @@ function createCPULineEdgeGeometry(
|
|||
|
||||
const maxSrcVertex = srcPos.length / 3 - 1;
|
||||
|
||||
// Get feature ID data from the original primitive
|
||||
const primitive = renderResources.runtimePrimitive.primitive;
|
||||
let srcFeatureIds = null;
|
||||
|
||||
// Try to get the first feature ID attribute (featureId_0)
|
||||
if (defined(primitive.featureIds) && primitive.featureIds.length > 0) {
|
||||
const firstFeatureId = primitive.featureIds[0];
|
||||
|
||||
if (firstFeatureId instanceof ModelComponents.FeatureIdAttribute) {
|
||||
// Try multiple possible semantic names
|
||||
const possibleSemantics = [
|
||||
`_FEATURE_ID_${firstFeatureId.setIndex}`,
|
||||
`FEATURE_ID_${firstFeatureId.setIndex}`,
|
||||
`_FEATURE_ID`,
|
||||
`FEATURE_ID`,
|
||||
firstFeatureId.attribute?.semantic, // Direct from the FeatureIdAttribute
|
||||
].filter(Boolean);
|
||||
|
||||
let featureIdAttribute = null;
|
||||
|
||||
for (const semanticName of possibleSemantics) {
|
||||
featureIdAttribute = ModelUtility.getAttributeBySemantic(
|
||||
primitive,
|
||||
semanticName,
|
||||
);
|
||||
}
|
||||
|
||||
// If still not found, try to access the attribute directly from firstFeatureId
|
||||
if (!defined(featureIdAttribute) && defined(firstFeatureId.attribute)) {
|
||||
featureIdAttribute = firstFeatureId.attribute;
|
||||
}
|
||||
|
||||
if (defined(featureIdAttribute)) {
|
||||
srcFeatureIds = defined(featureIdAttribute.typedArray)
|
||||
? featureIdAttribute.typedArray
|
||||
: ModelReader.readAttributeAsTypedArray(featureIdAttribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < numEdges; i++) {
|
||||
const a = edgeIndices[i * 2];
|
||||
const b = edgeIndices[i * 2 + 1];
|
||||
|
|
@ -531,8 +478,6 @@ function createCPULineEdgeGeometry(
|
|||
edgePosArray[p++] = 0;
|
||||
edgeTypeArray[i * 2] = 0;
|
||||
edgeTypeArray[i * 2 + 1] = 0;
|
||||
edgeFeatureIdArray[i * 2] = 0;
|
||||
edgeFeatureIdArray[i * 2 + 1] = 0;
|
||||
// Fill with default values
|
||||
const normalIdx = i * 2;
|
||||
silhouetteNormalArray[normalIdx * 3] = 0;
|
||||
|
|
@ -580,22 +525,6 @@ function createCPULineEdgeGeometry(
|
|||
edgeTypeArray[i * 2] = t;
|
||||
edgeTypeArray[i * 2 + 1] = t;
|
||||
|
||||
// Set feature ID for both edge endpoints
|
||||
let featureIdA = 0.0; // Default feature ID
|
||||
|
||||
if (defined(srcFeatureIds)) {
|
||||
// Get feature IDs from the original vertices
|
||||
if (a < srcFeatureIds.length) {
|
||||
featureIdA = srcFeatureIds[a];
|
||||
}
|
||||
}
|
||||
|
||||
// Use the feature ID of the first vertex for both edge endpoints
|
||||
// (alternatively, could use average or other logic)
|
||||
const edgeFeatureId = featureIdA;
|
||||
edgeFeatureIdArray[i * 2] = edgeFeatureId;
|
||||
edgeFeatureIdArray[i * 2 + 1] = edgeFeatureId;
|
||||
|
||||
// Add silhouette normal for silhouette edges (type 1)
|
||||
let normalX = 0,
|
||||
normalY = 0,
|
||||
|
|
@ -664,11 +593,6 @@ function createCPULineEdgeGeometry(
|
|||
typedArray: edgeTypeArray,
|
||||
usage: BufferUsage.STATIC_DRAW,
|
||||
});
|
||||
const edgeFeatureIdBuffer = Buffer.createVertexBuffer({
|
||||
context,
|
||||
typedArray: edgeFeatureIdArray,
|
||||
usage: BufferUsage.STATIC_DRAW,
|
||||
});
|
||||
const silhouetteNormalBuffer = Buffer.createVertexBuffer({
|
||||
context,
|
||||
typedArray: silhouetteNormalArray,
|
||||
|
|
@ -717,13 +641,6 @@ function createCPULineEdgeGeometry(
|
|||
componentDatatype: ComponentDatatype.FLOAT,
|
||||
normalize: false,
|
||||
},
|
||||
{
|
||||
index: edgeFeatureIdLocation,
|
||||
vertexBuffer: edgeFeatureIdBuffer,
|
||||
componentsPerAttribute: 1,
|
||||
componentDatatype: ComponentDatatype.FLOAT,
|
||||
normalize: false,
|
||||
},
|
||||
{
|
||||
index: silhouetteNormalLocation,
|
||||
vertexBuffer: silhouetteNormalBuffer,
|
||||
|
|
@ -753,22 +670,6 @@ function createCPULineEdgeGeometry(
|
|||
return undefined;
|
||||
}
|
||||
|
||||
// Feature ID statistics calculated but not currently used
|
||||
if (defined(srcFeatureIds)) {
|
||||
// Calculate min/max without spreading large arrays for potential debugging
|
||||
let min = edgeFeatureIdArray[0];
|
||||
let max = edgeFeatureIdArray[0];
|
||||
for (let i = 1; i < edgeFeatureIdArray.length; i++) {
|
||||
if (edgeFeatureIdArray[i] < min) {
|
||||
min = edgeFeatureIdArray[i];
|
||||
}
|
||||
if (edgeFeatureIdArray[i] > max) {
|
||||
max = edgeFeatureIdArray[i];
|
||||
}
|
||||
}
|
||||
// Range: min=${min}, max=${max}, unique=${new Set(edgeFeatureIdArray).size}
|
||||
}
|
||||
|
||||
return { vertexArray, indexBuffer, indexCount: totalVerts };
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
void edgeDetectionStage(inout vec4 color) {
|
||||
void edgeDetectionStage(inout vec4 color, inout FeatureIds featureIds) {
|
||||
if (u_isEdgePass) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -9,19 +9,10 @@ void edgeDetectionStage(inout vec4 color) {
|
|||
vec4 edgeId = texture(czm_edgeIdTexture, screenCoord);
|
||||
|
||||
if (edgeId.r > 0.0) {
|
||||
color = edgeColor;
|
||||
return;
|
||||
float edgeFeatureId = edgeId.g;
|
||||
|
||||
float currentFeatureId = 0.0;
|
||||
float currentFeatureId = float(featureIds.featureId_0);
|
||||
|
||||
#ifdef HAS_FEATURE_IDS
|
||||
currentFeatureId = float(featureIds.featureId_0);
|
||||
#endif
|
||||
|
||||
float featureIdDifference = abs(edgeFeatureId - currentFeatureId);
|
||||
|
||||
if (featureIdDifference < 0.5) {
|
||||
if (edgeFeatureId == currentFeatureId) {
|
||||
color = edgeColor;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ layout(location = 0) out vec4 out_FragColor;
|
|||
layout(location = 1) out vec4 out_id;
|
||||
#endif
|
||||
|
||||
void edgeVisibilityStage(inout vec4 color)
|
||||
void edgeVisibilityStage(inout vec4 color, inout FeatureIds featureIds)
|
||||
{
|
||||
#ifdef HAS_EDGE_VISIBILITY
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ void edgeVisibilityStage(inout vec4 color)
|
|||
#ifdef HAS_EDGE_VISIBILITY_MRT
|
||||
out_FragColor = edgeColor;
|
||||
out_id.r = edgeTypeInt; // Edge type
|
||||
out_id.g = v_edgeFeatureId; // Feature ID
|
||||
out_id.g = float(featureIds.featureId_0); // Feature ID from current geometry
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,8 +120,8 @@ void main()
|
|||
#endif
|
||||
|
||||
#ifdef HAS_EDGE_VISIBILITY
|
||||
edgeVisibilityStage(color);
|
||||
edgeDetectionStage(color);
|
||||
edgeVisibilityStage(color, featureIds);
|
||||
edgeDetectionStage(color, featureIds);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue