Skip to content

Commit

Permalink
Draft for fixing disappearing I3DM
Browse files Browse the repository at this point in the history
  • Loading branch information
javagl committed Aug 1, 2024
1 parent 32d0410 commit d381c1d
Showing 1 changed file with 63 additions and 2 deletions.
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

0 comments on commit d381c1d

Please sign in to comment.