Skip to content

Commit b45e794

Browse files
committed
Back out efb2f2d
Unfortunately, `Primitive.modelMatrix` is only useful in 3d-only situations. See #1486
1 parent bd1ceae commit b45e794

File tree

1 file changed

+43
-89
lines changed

1 file changed

+43
-89
lines changed

Source/DynamicScene/EllipsoidGeometryUpdater.js

+43-89
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ define(['../Core/Cartesian3',
5454

5555
var positionScratch;
5656
var orientationScratch;
57-
var radiiScratch;
5857
var matrix3Scratch;
5958

6059
var GeometryOptions = function(dynamicObject) {
@@ -305,11 +304,12 @@ define(['../Core/Cartesian3',
305304

306305
positionScratch = dynamicObject.position.getValue(Iso8601.MINIMUM_VALUE, positionScratch);
307306
orientationScratch = dynamicObject.orientation.getValue(Iso8601.MINIMUM_VALUE, orientationScratch);
307+
matrix3Scratch = Matrix3.fromQuaternion(orientationScratch, matrix3Scratch);
308308

309309
return new GeometryInstance({
310310
id : dynamicObject,
311311
geometry : new EllipsoidGeometry(this._options),
312-
modelMatrix : Matrix4.fromRotationTranslation(Matrix3.fromQuaternion(orientationScratch), positionScratch),
312+
modelMatrix : Matrix4.fromRotationTranslation(matrix3Scratch, positionScratch),
313313
attributes : attributes
314314
});
315315
};
@@ -340,11 +340,12 @@ define(['../Core/Cartesian3',
340340

341341
positionScratch = dynamicObject.position.getValue(Iso8601.MINIMUM_VALUE, positionScratch);
342342
orientationScratch = dynamicObject.orientation.getValue(Iso8601.MINIMUM_VALUE, orientationScratch);
343+
matrix3Scratch = Matrix3.fromQuaternion(orientationScratch, matrix3Scratch);
343344

344345
return new GeometryInstance({
345346
id : dynamicObject,
346347
geometry : new EllipsoidOutlineGeometry(this._options),
347-
modelMatrix : Matrix4.fromRotationTranslation(Matrix3.fromQuaternion(orientationScratch), positionScratch),
348+
modelMatrix : Matrix4.fromRotationTranslation(matrix3Scratch, positionScratch),
348349
attributes : {
349350
show : new ShowGeometryInstanceAttribute(isAvailable && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)),
350351
color : ColorGeometryInstanceAttribute.fromColor(isAvailable ? this._outlineColorProperty.getValue(time) : Color.BLACK)
@@ -488,17 +489,11 @@ define(['../Core/Cartesian3',
488489
* @private
489490
*/
490491
var DynamicGeometryUpdater = function(primitives, geometryUpdater) {
491-
this._dynamicObject = geometryUpdater._dynamicObject;
492492
this._primitives = primitives;
493493
this._primitive = undefined;
494494
this._outlinePrimitive = undefined;
495495
this._geometryUpdater = geometryUpdater;
496496
this._options = new GeometryOptions(geometryUpdater._dynamicObject);
497-
this._options.radii = new Cartesian3(1, 1, 1);
498-
this._modelMatrix = new Matrix4();
499-
this._material = undefined;
500-
this._attributes = undefined;
501-
this._outlineAttributes = undefined;
502497
};
503498

504499
DynamicGeometryUpdater.prototype.update = function(time) {
@@ -508,50 +503,46 @@ define(['../Core/Cartesian3',
508503
}
509504
//>>includeEnd('debug');
510505

511-
var dynamicObject = this._dynamicObject;
506+
var geometryUpdater = this._geometryUpdater;
507+
508+
if (defined(this._primitive)) {
509+
this._primitives.remove(this._primitive);
510+
}
511+
512+
if (defined(this._outlinePrimitive)) {
513+
this._primitives.remove(this._outlinePrimitive);
514+
}
515+
516+
var dynamicObject = geometryUpdater._dynamicObject;
512517
var ellipsoid = dynamicObject.ellipsoid;
513518
var show = ellipsoid.show;
514519

515520
if (!dynamicObject.isAvailable(time) || (defined(show) && !show.getValue(time))) {
516-
if (defined(this._primitive)) {
517-
this._primitive.show = false;
518-
}
519-
520-
if (defined(this._outlinePrimitive)) {
521-
this._outlinePrimitive.show = false;
522-
}
523521
return;
524522
}
525523

526-
//Compute attributes and material.
527-
var appearance;
528-
var showFill = !defined(ellipsoid.fill) || ellipsoid.fill.getValue(time);
529-
var showOutline = defined(ellipsoid.outline) && ellipsoid.outline.getValue(time);
530-
var outlineColor = defined(ellipsoid.outlineColor) ? ellipsoid.outlineColor.getValue(time) : Color.BLACK;
531-
var material = MaterialProperty.getValue(time, defaultValue(ellipsoid.material, defaultMaterial), this._material);
532-
this._material = material;
533-
534-
// Check properties that could trigger a primitive rebuild.
535-
var stackPartitionsProperty = ellipsoid.stackPartitions;
536-
var slicePartitionsProperty = ellipsoid.slicePartitions;
537-
var subdivisionsProperty = ellipsoid.subdivisions;
538-
var stackPartitions = defined(stackPartitionsProperty) ? stackPartitionsProperty.getValue(time) : undefined;
539-
var slicePartitions = defined(slicePartitionsProperty) ? slicePartitionsProperty.getValue(time) : undefined;
540-
var subdivisions = defined(subdivisionsProperty) ? subdivisionsProperty.getValue(time) : undefined;
541-
542524
var options = this._options;
525+
var position = dynamicObject.position;
526+
var orientation = dynamicObject.orientation;
527+
var radii = ellipsoid.radii;
528+
var stackPartitions = ellipsoid.stackPartitions;
529+
var slicePartitions = ellipsoid.slicePartitions;
530+
var subdivisions = ellipsoid.subdivisions;
531+
532+
positionScratch = position.getValue(time, positionScratch);
533+
orientationScratch = orientation.getValue(time, orientationScratch);
534+
matrix3Scratch = Matrix3.fromQuaternion(orientationScratch, matrix3Scratch);
535+
var modelMatrix = Matrix4.fromRotationTranslation(matrix3Scratch, positionScratch);
536+
537+
options.radii = radii.getValue(time, options.radii);
538+
options.stackPartitions = defined(stackPartitions) ? stackPartitions.getValue(time, options) : undefined;
539+
options.slicePartitions = defined(slicePartitions) ? slicePartitions.getValue(time, options) : undefined;
540+
options.subdivisions = defined(subdivisions) ? subdivisions.getValue(time) : undefined;
543541

544-
//We only rebuild the primitive if something other than the radii has changed
545-
//For the radii, we use unit sphere and then deform it with a scale matrix.
546-
var rebuildPrimitives = !defined(this._primitive) || options.stackPartitions !== stackPartitions || options.slicePartitions !== slicePartitions || options.subdivisions !== subdivisions;
547-
if (rebuildPrimitives) {
548-
options.stackPartitions = stackPartitions;
549-
options.slicePartitions = slicePartitions;
550-
options.subdivisions = subdivisions;
551-
552-
this._material = material;
553-
material = this._material;
554-
appearance = new MaterialAppearance({
542+
if (!defined(ellipsoid.fill) || ellipsoid.fill.getValue(time)) {
543+
this._material = MaterialProperty.getValue(time, geometryUpdater.fillMaterialProperty, this._material);
544+
var material = this._material;
545+
var appearance = new MaterialAppearance({
555546
material : material,
556547
faceForward : true,
557548
translucent : material.isTranslucent(),
@@ -562,23 +553,25 @@ define(['../Core/Cartesian3',
562553
this._primitive = new Primitive({
563554
geometryInstances : new GeometryInstance({
564555
id : dynamicObject,
565-
geometry : new EllipsoidGeometry(options)
556+
geometry : new EllipsoidGeometry(options),
557+
modelMatrix : modelMatrix
566558
}),
567559
appearance : appearance,
568-
asynchronous : false,
569-
attributes : {
570-
show : new ShowGeometryInstanceAttribute(showFill)
571-
}
560+
asynchronous : false
572561
});
573562
this._primitives.add(this._primitive);
563+
}
574564

565+
if (defined(ellipsoid.outline) && ellipsoid.outline.getValue(time)) {
575566
options.vertexFormat = PerInstanceColorAppearance.VERTEX_FORMAT;
567+
568+
var outlineColor = defined(ellipsoid.outlineColor) ? ellipsoid.outlineColor.getValue(time) : Color.BLACK;
576569
this._outlinePrimitive = new Primitive({
577570
geometryInstances : new GeometryInstance({
578571
id : dynamicObject,
579572
geometry : new EllipsoidOutlineGeometry(options),
573+
modelMatrix : modelMatrix,
580574
attributes : {
581-
show : new ShowGeometryInstanceAttribute(showOutline),
582575
color : ColorGeometryInstanceAttribute.fromColor(outlineColor)
583576
}
584577
}),
@@ -589,46 +582,7 @@ define(['../Core/Cartesian3',
589582
asynchronous : false
590583
});
591584
this._primitives.add(this._outlinePrimitive);
592-
593-
} else {
594-
//Update attributes only.
595-
var primitive = this._primitive;
596-
appearance = primitive.appearance;
597-
appearance.material = material;
598-
599-
var attributes = this._attributes;
600-
if (!defined(attributes)) {
601-
attributes = primitive.getGeometryInstanceAttributes(dynamicObject);
602-
this._attributes = attributes;
603-
}
604-
attributes.show = ShowGeometryInstanceAttribute.toValue(showFill, attributes.show);
605-
606-
var outlinePrimitive = this._outlinePrimitive;
607-
608-
var outlineAttributes = this._outlineAttributes;
609-
if (!defined(outlineAttributes)) {
610-
outlineAttributes = outlinePrimitive.getGeometryInstanceAttributes(dynamicObject);
611-
this._outlineAttributes = outlineAttributes;
612-
}
613-
outlineAttributes.show = ShowGeometryInstanceAttribute.toValue(showOutline, outlineAttributes.show);
614-
outlineAttributes.color = ColorGeometryInstanceAttribute.toValue(outlineColor, outlineAttributes.color);
615585
}
616-
617-
//Finally, compute and set the model matrices
618-
var positionProperty = dynamicObject.position;
619-
var orientationProperty = dynamicObject.orientation;
620-
var radiiProperty = ellipsoid.radii;
621-
622-
positionScratch = positionProperty.getValue(time, positionScratch);
623-
orientationScratch = orientationProperty.getValue(time, orientationScratch);
624-
matrix3Scratch = Matrix3.fromQuaternion(orientationScratch, matrix3Scratch);
625-
radiiScratch = radiiProperty.getValue(time, radiiScratch);
626-
627-
var modelMatrix = this._modelMatrix;
628-
modelMatrix = Matrix4.fromRotationTranslation(matrix3Scratch, positionScratch, modelMatrix);
629-
modelMatrix = Matrix4.multiplyByScale(modelMatrix, radiiScratch, modelMatrix);
630-
this._primitive.modelMatrix = modelMatrix;
631-
this._outlinePrimitive.modelMatrix = modelMatrix;
632586
};
633587

634588
DynamicGeometryUpdater.prototype.isDestroyed = function() {

0 commit comments

Comments
 (0)