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

Draft for fixing disappearing I3DM models #12105

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 63 additions & 2 deletions packages/engine/Source/Scene/Model/PrimitiveRenderResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import clone from "../../Core/clone.js";
import defined from "../../Core/defined.js";
import ModelUtility from "./ModelUtility.js";
import ModelLightingOptions from "./ModelLightingOptions.js";
import Matrix4 from "../../Core/Matrix4.js";

/**
* Each node may have many mesh primitives. Most model pipeline stages operate
Expand Down Expand Up @@ -232,15 +233,67 @@ function PrimitiveRenderResources(nodeRenderResources, runtimePrimitive) {
*/
this.primitiveType = primitive.primitiveType;

// For computing the `positionMin` and `positionMax` properties,
// the instancing translation (if present) has to be taken into
// account.
// The `positionMin` and `positionMax` are supposed to NOT take
// the node transform into account.
// So when the instancing translations are supposed to be applied
// in world space (as indicated by instances.transformInWorldSpace),
// then the instancing translations have to be multiplied with the
// inverse of the node transform, to eventually yield the true
// minimum/maximum after applying the node transform.

let instancingTranslationMin = this.runtimeNode.instancingTranslationMin;
let instancingTranslationMax = this.runtimeNode.instancingTranslationMax;

//*/
const instances = this.runtimeNode.node.instances;
if (defined(instances)) {
// TODO Is this check necessary?
if (
!defined(instancingTranslationMin) ||
!defined(instancingTranslationMax)
) {
console.log("Something wrong, they should be defined... I guess...");
}
if (instances.transformInWorldSpace) {
const nodeTransform = this.runtimeNode.computedTransform;
// TODO Use scratches here
const inverseNodeTransform = Matrix4.inverse(
nodeTransform,
new Matrix4()
);
instancingTranslationMin = Matrix4.multiplyByPoint(
inverseNodeTransform,
instancingTranslationMin,
new Cartesian3()
);
instancingTranslationMax = Matrix4.multiplyByPoint(
inverseNodeTransform,
instancingTranslationMax,
new Cartesian3()
);
}
}
//*/
const positionMinMax = ModelUtility.getPositionMinMax(
primitive,
this.runtimeNode.instancingTranslationMin,
this.runtimeNode.instancingTranslationMax
instancingTranslationMin,
instancingTranslationMax
);

/**
* The minimum position value for this primitive.
*
* This does not take into account the transform of the node that this
* primitive is attached to.
*
* But it does take into account any possible instancing transforms,
* multiplied with the inverse of the node transform. So transforming
* this position value with the node transform will yield the actual
* minimum position, including the instancing transforms.
*
* @type {Cartesian3}
* @readonly
*
Expand All @@ -251,6 +304,14 @@ function PrimitiveRenderResources(nodeRenderResources, runtimePrimitive) {
/**
* The maximum position value for this primitive.
*
* This does not take into account the transform of the node that this
* primitive is attached to.
*
* But it does take into account any possible instancing transforms,
* multiplied with the inverse of the node transform. So transforming
* this position value with the node transform will yield the actual
* maximum position, including the instancing transforms.
*
* @type {Cartesian3}
* @readonly
*
Expand Down
26 changes: 23 additions & 3 deletions packages/engine/Source/Scene/Model/buildDrawCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,31 @@ function buildDrawCommand(primitiveRenderResources, frameState) {

boundingSphere = BoundingSphere.transform(
primitiveRenderResources.boundingSphere,
modelMatrix,
primitiveRenderResources.boundingSphere
modelMatrix
);
}

console.log("buildDrawCommand");
console.log(" positionMin", primitiveRenderResources.positionMin);
console.log(" positionMax", primitiveRenderResources.positionMax);
console.log(
" instancingTranslationMin ",
primitiveRenderResources.runtimeNode.instancingTranslationMin
);
console.log(
" instancingTranslationMax ",
primitiveRenderResources.runtimeNode.instancingTranslationMax
);
console.log(
" node scale ",
primitiveRenderResources.runtimeNode.computedTransform[0]
);
console.log(
" instances transformInWorldSpace ",
primitiveRenderResources.runtimeNode.node?.instances?.transformInWorldSpace
);
console.log(" radius", primitiveRenderResources.boundingSphere.radius);

// Initialize render state with default values
let renderState = clone(
RenderState.fromCache(primitiveRenderResources.renderStateOptions),
Expand Down Expand Up @@ -117,7 +137,7 @@ function buildDrawCommand(primitiveRenderResources, frameState) {
pickId: pickId,
instanceCount: primitiveRenderResources.instanceCount,
primitiveType: primitiveRenderResources.primitiveType,
debugShowBoundingVolume: model.debugShowBoundingVolume,
debugShowBoundingVolume: true, //model.debugShowBoundingVolume,
castShadows: castShadows,
receiveShadows: receiveShadows,
});
Expand Down
Loading