Skip to content

Commit

Permalink
#210: extending the mesh structure to support morph targets
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliano committed Feb 24, 2017
1 parent f8f60be commit 1de1427
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
39 changes: 39 additions & 0 deletions specification/2.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,45 @@ Valid attribute semantic property names include `POSITION`, `NORMAL`, `TEXCOORD`

> **Implementation note:** Each primitive corresponds to one WebGL draw call (engines are, of course, free to batch draw calls). When a primitive's `indices` property is defined, it references the accessor to use for index data, and GL's `drawElements` function should be used. When the `indices` property is not defined, GL's `drawArrays` function should be used with a count equal to the count property of any of the accessors referenced by the `attributes` property (they are all equal for a given primitive).
#### Morph Targets

Morph Targets are defined by extending the Mesh concept.
A Morph Target is a morphable Mesh where primitives' attributes are obtained by adding the original attributes to a weighted sum of targets attributes (this operation corresponds to COLLADA's `RELATIVE` blending method).
Morph Targets are implemented via the `targets` property defined in the Mesh `primitives`. Each target in the `targets` array is a dictionary mapping a primitive attribute to a Morph Target displacement, currently only two attributes ('POSITION' and 'NORMAL') are supported. All primitives are required to list the same number of `targets` in the same order.
The `weights` array is optional, it stores the default targets weights, in the absence of animations the primitives attributes are resolved using these weights. When this property is missing the default targets weights are assumed to be zero.

The following example extends the Mesh defined in the previous example to a morphable one by adding two Morph Targets:
```json
{
"meshes": [
{
"primitives": [
{
"attributes": {
"NORMAL": 25,
"POSITION": 23,
"TEXCOORD_0": 27
},
"indices": 21,
"material": 3,
"mode": 4,
"targets": [
{
"NORMAL": 35,
"POSITION": 33,
},
{
"NORMAL": 45,
"POSITION": 43,
},
]
}
],
"weights": [0, 0.5]
}
]
}
```

### Skins

Expand Down
8 changes: 8 additions & 0 deletions specification/2.0/schema/mesh.primitive.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"default" : 4,
"gltf_detailedDescription" : "The type of primitives to render. All valid values correspond to WebGL enums."
},
"targets" : {
"type" : "array",
"description" : "An array of Morph Targets, each Morph Target is a dictionary mapping attributes (only "POSITION" and "NORMAL" supported) to their deviations in the Morph Target.",
"items" : {
"$ref" : "mesh.primitive.target.schema.json"
},
"minItems" : 0
},
"extensions" : {},
"extras" : {}
},
Expand Down
6 changes: 6 additions & 0 deletions specification/2.0/schema/mesh.primitive.target.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema" : "http://json-schema.org/draft-04/schema",
"title" : "target",
"allOf" : [ { "$ref" : "glTFid.schema.json" } ],
"description" : "A dictionary object specifying attributes displacements in a Morph Target, where each key corresponds to one of the two supported attribute semantic ("POSITION" or "NORMAL") and each value is the index of the accessor containing the attribute displacements' data."
}
10 changes: 9 additions & 1 deletion specification/2.0/schema/mesh.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
},
"name" : {},
"extensions" : {},
"extras" : {}
"extras" : {},
"weights" : {
"type" : "array",
"description" : "Array of weights to be applied to the Morph Targets.",
"items" : {
"type" : "number"
},
"minItems" : 0
}
},
"additionalProperties" : false,
"required" : ["primitives"]
Expand Down

0 comments on commit 1de1427

Please sign in to comment.