Skip to content

Commit

Permalink
Merge pull request #10384 from CesiumGS/model-experimental-2d-cv-support
Browse files Browse the repository at this point in the history
Add 2D / CV support to tilesets using ModelExperimental
  • Loading branch information
ptrgags authored May 25, 2022
2 parents 6dc5d70 + c0dc5df commit b525bb8
Show file tree
Hide file tree
Showing 31 changed files with 1,851 additions and 473 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Added `IndexDatatype.fromTypedArray`. [#10350](https://github.com/CesiumGS/cesium/pull/10350)
- Added `ModelAnimationCollection.animateWhilePaused` and `ModelAnimation.animationTime` to allow explicit control over a model's animations. [#9339](https://github.com/CesiumGS/cesium/pull/9339)
- Replaced `options.gltf` with `options.url` in `ModelExperimental.fromGltf`. [#10371](https://github.com/CesiumGS/cesium/pull/10371)
- Added support for 2D / CV mode for non-instanced tilesets rendered with `ModelExperimental`. [#10384](https://github.com/CesiumGS/cesium/pull/10384)

##### Fixes :wrench:

Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/FrameState.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function FrameState(context, creditDisplay, jobScheduler) {
this.afterRender = [];

/**
* Gets whether or not to optimized for 3D only.
* Gets whether or not to optimize for 3D only.
*
* @type {Boolean}
* @default false
Expand Down
46 changes: 17 additions & 29 deletions Source/Scene/GltfIndexBufferLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ComponentDatatype from "../Core/ComponentDatatype.js";
import defaultValue from "../Core/defaultValue.js";
import defer from "../Core/defer.js";
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import IndexDatatype from "../Core/IndexDatatype.js";
import Buffer from "../Renderer/Buffer.js";
import BufferUsage from "../Renderer/BufferUsage.js";
Expand All @@ -29,8 +30,8 @@ import ResourceLoaderState from "./ResourceLoaderState.js";
* @param {Object} [options.draco] The Draco extension object.
* @param {String} [options.cacheKey] The cache key of the resource.
* @param {Boolean} [options.asynchronous=true] Determines if WebGL resource creation will be spread out over several frames or block until all WebGL resources are created.
* @param {Boolean} [options.loadAsTypedArray=false] Load index buffer as a typed array instead of a GPU index buffer.
* @param {Boolean} [options.loadForWireframe=false] Load index buffer as a typed array in order to generate wireframes in WebGL1. This will be ignored if using WebGL2.
* @param {Boolean} [options.loadBuffer=false] Load the index buffer as a GPU index buffer.
* @param {Boolean} [options.loadTypedArray=false] Load the index buffer as a typed array.
* @private
*/
export default function GltfIndexBufferLoader(options) {
Expand All @@ -43,15 +44,20 @@ export default function GltfIndexBufferLoader(options) {
const draco = options.draco;
const cacheKey = options.cacheKey;
const asynchronous = defaultValue(options.asynchronous, true);
const loadAsTypedArray = defaultValue(options.loadAsTypedArray, false);
const loadForWireframe = defaultValue(options.loadForWireframe, false);
const loadBuffer = defaultValue(options.loadBuffer, false);
const loadTypedArray = defaultValue(options.loadTypedArray, false);

//>>includeStart('debug', pragmas.debug);
Check.typeOf.func("options.resourceCache", resourceCache);
Check.typeOf.object("options.gltf", gltf);
Check.typeOf.number("options.accessorId", accessorId);
Check.typeOf.object("options.gltfResource", gltfResource);
Check.typeOf.object("options.baseResource", baseResource);
if (!loadBuffer && !loadTypedArray) {
throw new DeveloperError(
"At least one of loadBuffer and loadTypedArray must be true."
);
}
//>>includeEnd('debug');

const indexDatatype = gltf.accessors[accessorId].componentType;
Expand All @@ -65,8 +71,8 @@ export default function GltfIndexBufferLoader(options) {
this._draco = draco;
this._cacheKey = cacheKey;
this._asynchronous = asynchronous;
this._loadAsTypedArray = loadAsTypedArray;
this._loadForWireframe = loadForWireframe;
this._loadBuffer = loadBuffer;
this._loadTypedArray = loadTypedArray;
this._bufferViewLoader = undefined;
this._dracoLoader = undefined;
this._typedArray = undefined;
Expand Down Expand Up @@ -110,8 +116,7 @@ Object.defineProperties(GltfIndexBufferLoader.prototype, {
},
},
/**
* The index buffer. This is only defined when <code>loadAsTypedArray</code> is false
* or when <code>loadForWireframe</code> is false while using WebGL1.
* The index buffer. This is only defined when <code>loadBuffer</code> is true.
*
* @memberof GltfIndexBufferLoader.prototype
*
Expand All @@ -125,8 +130,7 @@ Object.defineProperties(GltfIndexBufferLoader.prototype, {
},
},
/**
* The typed array containing indices. This is only defined when <code>loadAsTypedArray</code> is true
* or when <code>loadForWireframe</code> is true while using WebGL1.
* The typed array containing indices. This is only defined when <code>loadTypedArray</code> is true.
*
* @memberof GltfIndexBufferLoader.prototype
*
Expand Down Expand Up @@ -338,25 +342,8 @@ GltfIndexBufferLoader.prototype.process = function (frameState) {
return;
}

// WebGL1 has no way to retrieve the contents of buffers that are
// on the GPU. Therefore, the index buffer must be stored in CPU memory
// to generate wireframes for models.
const useWebgl2 = frameState.context.webgl2;
const loadTypedArrayForWireframe = !useWebgl2 && this._loadForWireframe;
if (this._loadAsTypedArray || loadTypedArrayForWireframe) {
// Unload everything except the typed array
this.unload();

this._typedArray = typedArray;
this._state = ResourceLoaderState.READY;
this._promise.resolve(this);

return;
}

let buffer;

if (this._asynchronous) {
if (this._loadBuffer && this._asynchronous) {
const indexBufferJob = scratchIndexBufferJob;
indexBufferJob.set(typedArray, indexDatatype, frameState.context);
const jobScheduler = frameState.jobScheduler;
Expand All @@ -365,14 +352,15 @@ GltfIndexBufferLoader.prototype.process = function (frameState) {
return;
}
buffer = indexBufferJob.buffer;
} else {
} else if (this._loadBuffer) {
buffer = createIndexBuffer(typedArray, indexDatatype, frameState.context);
}

// Unload everything except the index buffer
this.unload();

this._buffer = buffer;
this._typedArray = this._loadTypedArray ? typedArray : undefined;
this._state = ResourceLoaderState.READY;
this._promise.resolve(this);
};
Expand Down
Loading

0 comments on commit b525bb8

Please sign in to comment.