Skip to content

Commit

Permalink
Implement reading dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
umberto-sonnino committed Nov 8, 2019
1 parent 53395ac commit bcdd912
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 4 additions & 3 deletions source/ActorImage.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import ActorSkinnable from "./ActorSkinnable.js";
import ActorDrawable from "./ActorDrawable.js";
import {vec2, mat2d} from "gl-matrix";
import {vec2} from "gl-matrix";
import Graphics from "./Graphics.js";

const White = [1.0, 1.0, 1.0, 1.0];
export default class ActorImage extends ActorSkinnable(ActorDrawable)
{
constructor()
Expand All @@ -12,6 +11,7 @@ export default class ActorImage extends ActorSkinnable(ActorDrawable)
this._AtlasIndex = -1;
this._NumVertices = 0;
this._Vertices = null;
this._DynamicUV = null;
this._Triangles = null;
this._IsInstance = false;

Expand Down Expand Up @@ -57,7 +57,7 @@ export default class ActorImage extends ActorSkinnable(ActorDrawable)
{
let v = worldVertices[i];
let x = v[0];
let y = v[1]
let y = v[1];
if(x < min_x)
{
min_x = x;
Expand Down Expand Up @@ -314,6 +314,7 @@ export default class ActorImage extends ActorSkinnable(ActorDrawable)
this._VertexStride = node._VertexStride;
this._Vertices = node._Vertices;
this._Triangles = node._Triangles;
this._DynamicUV = node._DynamicUV;
// N.B. actor.initialize must've been called before instancing.
this._VertexBuffer = node._VertexBuffer;
this._IndexBuffer = node._IndexBuffer;
Expand Down
12 changes: 12 additions & 0 deletions source/ActorLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,18 @@ function _ReadActorImage(version, reader, component)
component._VertexStride = vertexStride;
component._Vertices = new Float32Array(numVertices * vertexStride);
reader.readFloat32Array(component._Vertices, "vertices");

// Version 24 includes packing the original UV coords if the
// image was marked for dynamic runtime swapping.
if (version >= 24)
{
const isDynamic = reader.readBool("isDynamic");
if (isDynamic)
{
component._DynamicUV = new Float32Array(numVertices*2);
reader.readFloat32Array(component._DynamicUV, "uv");
}
}

const numTris = reader.readUint32("numTriangles");
component._Triangles = new Uint16Array(numTris * 3);
Expand Down

0 comments on commit bcdd912

Please sign in to comment.