Skip to content

Commit 4e871eb

Browse files
mvaligurskyvkalpiaswilleastcott
authored
RenderComponent - new component to replace ModelComponent (playcanvas#2488)
* RenderComponent - new component to replace ModelComponent * small optimization * removed unused properties from cloning * using instanceof to test type * lint * moved getShapePrimitive to procedural instead of component system * small fixes * small fix * Squashed commit of the following: commit 199cc41 Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Wed Sep 2 11:52:29 2020 +0100 Changes to Camera.screenToWorld to improve precision with large frustum depth range (playcanvas#2400) commit e2a1517 Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Tue Sep 1 10:44:37 2020 +0100 [Fix] Shader parameters set on Material or MeshInstance are used in all passes (playcanvas#2391) * [Fix] Shader parameters set on Material or MeshInstance are used in all passes * additional cleanup and function reuse for unsetting meshinstance uniform overrides commit 3cc6588 Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Tue Sep 1 09:36:44 2020 +0100 Separated SkinInstance class into its own file skin-instance.js (playcanvas#2394) commit 525fc08 Author: moka <core@moka.co> Date: Tue Sep 1 00:42:30 2020 +0200 WebXR Input Sources: retrieve most relevant transforms of the parent (playcanvas#2395) * retrieve most relevant transforms of the parent * fix commit d96a75e Author: Aidin Abedi <aidinabedi@gmail.com> Date: Thu Aug 27 19:55:24 2020 +0200 Improve clear-coat material and add KHR_materials_clearcoat support in glTF parser (playcanvas#2377) * add clear coat shader chunks * make clear coat shader variables global (because we'll need to access them from other chunks) * add clearcoat parameters to standard material * use shader chunks when clear coat is enabled * add pc.StandardMaterial#clearCoatBumpiness * document new clear coat properties * add support for KHR_materials_clearcoat in gltf parser * add temp workaround for replicating glTF clear-coat visuals * minor documentation tweak Co-authored-by: Ray Tran <raytranuk@users.noreply.github.com> commit 4d5f59d Author: Aidin Abedi <aidinabedi@gmail.com> Date: Thu Aug 27 19:52:59 2020 +0200 Fix normals when mesh has both two-sided material and negative scale (playcanvas#2375) * fix: flip back-facing normals for double-sided materials depending on their angle towards the eye the original method of using gl_FrontFacing doesn't work for mirrored geometry * refactor: rename normalSign to normalDirSign Co-authored-by: Anders Gallon <anders.gallon@animech.com> commit 8600fc6 Author: Elliott Thompson <ellth92@gmail.com> Date: Thu Aug 27 16:05:05 2020 +0100 updates the anim component to accept transitions that have their source state set to any state (playcanvas#2390) commit 6ee5309 Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Thu Aug 27 11:38:36 2020 +0100 MeshInstance frustum culling - small refactor (playcanvas#2389) * MeshInstance frustum culling - small refactor * creating BoundingSphere instead of object with similar properties * removed unnecessary parameters commit c8c9b92 Author: zachpeterpaul <49728898+zachpeterpaul@users.noreply.github.com> Date: Wed Aug 26 16:41:02 2020 -0700 set entity._template to true for template root (playcanvas#2384) Co-authored-by: zachppaul <zachppaul@gmail.com> commit 7b9177d Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Wed Aug 26 15:03:44 2020 +0100 [Fix] Texture based morphing would not update when all weights are 0 (playcanvas#2387) commit 5ad2185 Author: Steven <yaustar@users.noreply.github.com> Date: Tue Aug 25 11:08:18 2020 +0100 Add hit-test to optional XR features (playcanvas#2381) Fixes hit-test when launched on hand held device Co-authored-by: Steven Yau <syau@snaphcat.com> commit 8fbea05 Author: Will Eastcott <will@playcanvas.com> Date: Thu Aug 20 11:11:29 2020 +0100 Update NPM dependencies (playcanvas#2370) * Update NPM dependencies * Lint fix commit c1b132b Author: Donovan Hutchence <slimbuck7@gmail.com> Date: Wed Aug 19 16:18:23 2020 +0100 [VERSION] v1.35.0-dev commit 71086a3 Author: Donovan Hutchence <slimbuck7@gmail.com> Date: Wed Aug 19 16:18:23 2020 +0100 [RELEASE] v1.34.0 commit d8113fd Author: Donovan Hutchence <slimbuck7@gmail.com> Date: Wed Aug 19 14:22:43 2020 +0100 [FIX] Compile fix (playcanvas#2368) * compile fix * run build:all during ci checks commit 0626613 Author: Donovan Hutchence <slimbuck7@gmail.com> Date: Wed Aug 19 11:05:48 2020 +0100 add test when patching container multiple times (playcanvas#2367) commit d1f1555 Author: Vaios Kalpias Ilias <vkalpias@gmail.com> Date: Wed Aug 19 02:25:50 2020 -0700 Add documentation for pc.Element#mask (playcanvas#2366) commit 3a3d41c Author: Elliott Thompson <ellth92@gmail.com> Date: Wed Aug 19 10:25:28 2020 +0100 Anim optimizations (playcanvas#2354) * optimize the setting of animated properties in the anim binder commit d103cec Author: Steven <yaustar@users.noreply.github.com> Date: Wed Aug 19 10:24:36 2020 +0100 Added example code for curve and curve set (playcanvas#2353) * Added example code for curve and curve set Also fixes: playcanvas/developer-site#119 * Fixed lint * Fixed example spacing again * Reverted change to gampad on xrinput Co-authored-by: Steven Yau <syau@snaphcat.com> commit e51cf8e Author: Donovan Hutchence <slimbuck7@gmail.com> Date: Tue Aug 18 19:05:06 2020 +0100 Specify basis URL config (playcanvas#2359) * construct node hierarchy even when no model exists commit 8e47386 Author: Donovan Hutchence <slimbuck7@gmail.com> Date: Tue Aug 18 18:19:58 2020 +0100 construct node hierarchy even when no model exists (playcanvas#2358) commit bb94f0d Author: Vaios Kalpias Ilias <vkalpias@gmail.com> Date: Mon Aug 17 11:10:06 2020 -0700 Adding support for json script attributes with a schema (1 level deep) (playcanvas#2234) commit e53818f Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Tue Aug 11 16:24:15 2020 +0100 [Fix] Glb converts 32bit index buffer to 16 if device does not support it (playcanvas#2349) * [Fix] Glb converts 32bit index buffer to 16 if device does not support it * simpler code commit 0b529cb Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Tue Aug 11 16:23:07 2020 +0100 [Fix] gpu size calculation for PIXELFORMAT_L8_A8 and mipmaps (playcanvas#2350) * [Fix] gpu size calculation for PIXELFORMAT_L8_A8 and mipmaps * lint fix commit 75cebd3 Author: Benjamin Cabé <kartben@users.noreply.github.com> Date: Tue Aug 11 09:52:29 2020 +0200 Fix spelling for Arm (playcanvas#2344) commit ea66160 Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Mon Aug 10 15:16:47 2020 +0100 [Fix] improve compatibility of example with older mobile devices (playcanvas#2348) commit 3e9ccc9 Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Mon Aug 10 14:27:44 2020 +0100 [Fix] Mini-stats uses 16bit index buffer insead of 32 (playcanvas#2347) - makes it compatible with devices which dont support 32bit indices * skin instance import fix * build fixes * Squashed commit of the following: commit ad6fd49 Author: Elliott Thompson <ellth92@gmail.com> Date: Fri Sep 18 15:14:20 2020 +0100 update the anim controller update function to fix certain transition states (playcanvas#2434) commit 3b9983c Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Thu Sep 17 17:57:11 2020 +0100 Mini-stats update with functionality and flexibility (playcanvas#2428) * Mini-stats - separated file into per-class files. * fixed typo in comment * implemented new features * lint fix * small improvements * small changes (white text, black clear color, smaller gaps between graphs) * text labels are slightly darker than numbers * tracking basic frame timing and drawCall count even in release build * spacing updates * black background when graph is disabled * size adjustement commit 5389039 Author: moka <core@moka.co> Date: Wed Sep 16 00:03:00 2020 +0200 [FIX] tags remove error (playcanvas#2432) commit 4b711a7 Author: imgbot[bot] <31301654+imgbot[bot]@users.noreply.github.com> Date: Tue Sep 15 16:29:08 2020 +0100 [ImgBot] Optimize images (playcanvas#2430) /examples/assets/textures/normal-map.png -- 736.03kb -> 595.91kb (19.04%) Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com> Co-authored-by: ImgBotApp <ImgBotHelp@gmail.com> commit 0f14984 Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Tue Sep 15 15:18:30 2020 +0100 Refraction engine example and small related engine fix (playcanvas#2429) * Refraction engine example and small related engine fix * small change in how grab texture is set up to only use public interface * offset centering * using mesh UVs to sample offset texture instead of screen position * renamed to grab-pass commit 5b82eb9 Author: moka <core@moka.co> Date: Thu Sep 10 18:58:56 2020 +0200 expose session and frame for WebXR (playcanvas#2422) commit 8746592 Author: Ray Tran <raytranuk@users.noreply.github.com> Date: Wed Sep 9 09:54:37 2020 +0100 Warning added when element input is enabled, but no pc.ElementInput is created to fire input events (playcanvas#2419) Warning added when element input is enabled, but no pc.ElementInput is created to fire input events This will greatly help debugging a problem I wasted hours on - where element input event were not firing without any indication of why. commit 6279a2b Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Tue Sep 8 19:26:46 2020 +0100 Frustum culling on camera created by code defaults to true (playcanvas#2415) commit f2476b3 Author: Donovan Hutchence <slimbuck7@gmail.com> Date: Tue Sep 8 15:32:06 2020 +0100 [VERSION] v1.36.0-dev commit 100604b Author: Donovan Hutchence <slimbuck7@gmail.com> Date: Tue Sep 8 15:32:06 2020 +0100 [RELEASE] v1.35.0 commit e5d6bca Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Mon Sep 7 16:21:26 2020 +0100 [Fix] Supporting pass specific mesh-instance parameters as they are used by the Editor (playcanvas#2411) commit e129194 Author: Donovan Hutchence <slimbuck7@gmail.com> Date: Mon Sep 7 12:17:08 2020 +0100 Simplify binder logic (playcanvas#2401) * simplify binder * invoke setter when driving vector members commit 9cedb85 Author: Ray Tran <raytranuk@users.noreply.github.com> Date: Fri Sep 4 17:08:39 2020 +0100 Revert "Fix normals when mesh has both two-sided material and negative scale (playcanvas#2375)" (playcanvas#2406) This reverts commit 4d5f59d. # Conflicts: # src/graphics/program-lib/programs/standard.js commit 55e477a Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Fri Sep 4 15:06:39 2020 +0100 [Fix] Fixing return type of Entity.findComponents to be an array (playcanvas#2405) commit 0e3022c Author: zachpeterpaul <49728898+zachpeterpaul@users.noreply.github.com> Date: Wed Sep 2 10:24:11 2020 -0700 Support for a more compressed scene file format (playcanvas#2294) * initial decompress * do nothing without the compressed field * move decompress data * decompress in template * decompress in hierarchy * use underscores with private vars * rm else return * refactor parser for speed * rm expanding entities in templates * decompress entities only * move decompress to scene parser * initial decompress * handle triple vectors * reorder array and map check * change map check * rename fields * use field map array * edits for lint * comments in decompress * move decompress call to parser * add utils comments Co-authored-by: zachppaul <zachppaul@gmail.com> * Squashed commit of the following: commit d369b82 Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Wed Oct 7 10:58:40 2020 +0100 Optimized culling solution for skinned meshes (playcanvas#2435) * ModelComponent can specify oversize bounding box and disable expensive skinned bounds update * es5 compatibility commit f1692a6 Author: Will Eastcott <will@playcanvas.com> Date: Mon Oct 5 20:44:34 2020 +0100 [FIX] Minor corrections to Typescript definitions (playcanvas#2459) * [FIX] Minor corrections to Typescript definitions * Handle all function signatures for pc.Tags commit 524aeb0 Author: Elliott Thompson <ellth92@gmail.com> Date: Thu Oct 1 17:43:09 2020 +0100 update transition offset jsdoc and fix the state timeline duration property (playcanvas#2457) commit bcf1b3f Author: Elliott Thompson <ellth92@gmail.com> Date: Thu Oct 1 16:47:06 2020 +0100 AnimComponent - Blend Trees (playcanvas#2443) * anim component - blend trees commit b2243ff Author: moka <core@moka.co> Date: Wed Sep 30 16:12:52 2020 +0300 add particle define to particle shaders (playcanvas#2454) commit 7630827 Author: Steven <yaustar@users.noreply.github.com> Date: Tue Sep 29 16:59:02 2020 +0100 Call upgradeDataSchema if there is no error (playcanvas#2450) Co-authored-by: Steven Yau <syau@snaphcat.com> commit db49fe8 Author: moka <core@moka.co> Date: Tue Sep 29 18:58:52 2020 +0300 WebXR optionalFeatures options and change to `start` method (playcanvas#2397) * WebXR optionalFeatures options and change to `start` method * corrections commit 7e0f0a5 Author: Donovan Hutchence <slimbuck7@gmail.com> Date: Tue Sep 29 12:43:32 2020 +0100 [VERSION] v1.36.0-dev commit 3317bcf Author: Donovan Hutchence <slimbuck7@gmail.com> Date: Tue Sep 29 12:43:32 2020 +0100 [RELEASE] v1.35.1 commit a617df9 Author: Steven <yaustar@users.noreply.github.com> Date: Fri Sep 25 14:29:33 2020 +0100 Removes global data when Component System is destroyed (playcanvas#2448) Fixes playcanvas#2442 Co-authored-by: Steven Yau <syau@snaphcat.com> commit 0a22646 Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Fri Sep 25 09:59:17 2020 +0100 Fix for instanced rendering VB setup for the second eye in VR (playcanvas#2446) commit 06b6e2f Author: Kotov Oleg <oleg.sveshnickov@yandex.ru> Date: Tue Sep 22 03:06:43 2020 +0300 [FIX] Copy paste typo in Vec2 and Vec3 classes (playcanvas#2436) * Update vec2.js Documentation copypasta fix * Update vec3.js commit ad6fd49 Author: Elliott Thompson <ellth92@gmail.com> Date: Fri Sep 18 15:14:20 2020 +0100 update the anim controller update function to fix certain transition states (playcanvas#2434) commit 3b9983c Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Thu Sep 17 17:57:11 2020 +0100 Mini-stats update with functionality and flexibility (playcanvas#2428) * Mini-stats - separated file into per-class files. * fixed typo in comment * implemented new features * lint fix * small improvements * small changes (white text, black clear color, smaller gaps between graphs) * text labels are slightly darker than numbers * tracking basic frame timing and drawCall count even in release build * spacing updates * black background when graph is disabled * size adjustement commit 5389039 Author: moka <core@moka.co> Date: Wed Sep 16 00:03:00 2020 +0200 [FIX] tags remove error (playcanvas#2432) commit 4b711a7 Author: imgbot[bot] <31301654+imgbot[bot]@users.noreply.github.com> Date: Tue Sep 15 16:29:08 2020 +0100 [ImgBot] Optimize images (playcanvas#2430) /examples/assets/textures/normal-map.png -- 736.03kb -> 595.91kb (19.04%) Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com> Co-authored-by: ImgBotApp <ImgBotHelp@gmail.com> commit 0f14984 Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Tue Sep 15 15:18:30 2020 +0100 Refraction engine example and small related engine fix (playcanvas#2429) * Refraction engine example and small related engine fix * small change in how grab texture is set up to only use public interface * offset centering * using mesh UVs to sample offset texture instead of screen position * renamed to grab-pass commit 5b82eb9 Author: moka <core@moka.co> Date: Thu Sep 10 18:58:56 2020 +0200 expose session and frame for WebXR (playcanvas#2422) commit 8746592 Author: Ray Tran <raytranuk@users.noreply.github.com> Date: Wed Sep 9 09:54:37 2020 +0100 Warning added when element input is enabled, but no pc.ElementInput is created to fire input events (playcanvas#2419) Warning added when element input is enabled, but no pc.ElementInput is created to fire input events This will greatly help debugging a problem I wasted hours on - where element input event were not firing without any indication of why. commit 6279a2b Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Tue Sep 8 19:26:46 2020 +0100 Frustum culling on camera created by code defaults to true (playcanvas#2415) commit f2476b3 Author: Donovan Hutchence <slimbuck7@gmail.com> Date: Tue Sep 8 15:32:06 2020 +0100 [VERSION] v1.36.0-dev commit 100604b Author: Donovan Hutchence <slimbuck7@gmail.com> Date: Tue Sep 8 15:32:06 2020 +0100 [RELEASE] v1.35.0 commit e5d6bca Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Mon Sep 7 16:21:26 2020 +0100 [Fix] Supporting pass specific mesh-instance parameters as they are used by the Editor (playcanvas#2411) commit e129194 Author: Donovan Hutchence <slimbuck7@gmail.com> Date: Mon Sep 7 12:17:08 2020 +0100 Simplify binder logic (playcanvas#2401) * simplify binder * invoke setter when driving vector members commit 9cedb85 Author: Ray Tran <raytranuk@users.noreply.github.com> Date: Fri Sep 4 17:08:39 2020 +0100 Revert "Fix normals when mesh has both two-sided material and negative scale (playcanvas#2375)" (playcanvas#2406) This reverts commit 4d5f59d. # Conflicts: # src/graphics/program-lib/programs/standard.js commit 55e477a Author: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Fri Sep 4 15:06:39 2020 +0100 [Fix] Fixing return type of Entity.findComponents to be an array (playcanvas#2405) commit 0e3022c Author: zachpeterpaul <49728898+zachpeterpaul@users.noreply.github.com> Date: Wed Sep 2 10:24:11 2020 -0700 Support for a more compressed scene file format (playcanvas#2294) * initial decompress * do nothing without the compressed field * move decompress data * decompress in template * decompress in hierarchy * use underscores with private vars * rm else return * refactor parser for speed * rm expanding entities in templates * decompress entities only * move decompress to scene parser * initial decompress * handle triple vectors * reorder array and map check * change map check * rename fields * use field map array * edits for lint * comments in decompress * move decompress call to parser * add utils comments Co-authored-by: zachppaul <zachppaul@gmail.com> * render component support for override aabb * render asset + loading, WIP * small fix * asset property on render component * fix to render component * Fix asset loading for render component and relevant assets * Remove mesh instances when render asset is removed or unloaded * Fix meshInstances set when changing render type * clean up * Fix render asset example * Lint fixes * render.material support is back * update to material property * Documented asset, materialAssets for render component * render component engine examples - new baking example showing render component baking support�, adjusted few other examples to use render component * meshinstance cleanup * clear assets on remove * clean up meshInstances when changing asset type * single block for all properties * Reset to default material if necessary * Always create materialReferences even if value of materialAssets[i] is null * Switch to materialAssets[0] when the type changes unless 'material' has been set to something other than the default material * comment fixes, memory release improvement * Fix comment * Various fixes for render asset loader * Handle container asset remove * Added RenderComponent#rootBone and fixed some issues with cloning render components * Added docs for rootBone * spacing * find root bone in postInitialize * fixing glb-loader not calling callback when there are not buffers to load * skin and morph instances created when render component connects to render asset * fixed rootBone test * missing morph instance import * handles texture removal from asset that is not loaded by checking for null * fixing inheritance for skin batch instance * fix to render component asset release when type changes * Subscribe to set:meshes event using 'on' not 'once' * null check * comment improvement * one space less * Resolve rootBone entities in RenderComponentSystem's postInitialize * moved empty glb handling to separte glb to release earlier * unused import * removed empty line * comment improvement * added comments * improved model cleanup * Fire set:entity event in EntityReference when entity changes, Use EntityReference for render component's rootBone * function rename: _onRootBoneChanged * comment typo fix Co-authored-by: Will Eastcott <will@playcanvas.com> * documentation name fix * removed engine examples from this PR, those are in separate PR now Co-authored-by: Vaios Kalpias Ilias <vkalpias@gmail.com> Co-authored-by: Will Eastcott <will@playcanvas.com>
1 parent 151967a commit 4e871eb

24 files changed

+1534
-291
lines changed

src/anim/anim.js

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,26 @@ function DefaultAnimBinder(graph) {
640640
};
641641
flatten(graph);
642642

643+
var findMeshInstances = function (node) {
644+
645+
// walk up to the first parent node of entity type (skips internal nodes of Model)
646+
var object = node;
647+
while (object && !(object instanceof Entity)) {
648+
object = object.parent;
649+
}
650+
651+
// get meshInstances from either model or render component
652+
var meshInstances;
653+
if (object) {
654+
if (object.render) {
655+
meshInstances = object.render.meshInstances;
656+
} else if (object.model) {
657+
meshInstances = object.model.meshInstances;
658+
}
659+
}
660+
return meshInstances;
661+
};
662+
643663
this.nodes = nodes; // map of node name -> { node, count }
644664
this.activeNodes = []; // list of active nodes
645665
this.handlers = {
@@ -668,63 +688,50 @@ function DefaultAnimBinder(graph) {
668688
},
669689

670690
'weights': function (node) {
671-
var object = node;
672-
while (object && object.constructor !== Entity) {
673-
object = object.parent;
674-
}
675-
if (!object ||
676-
!object.model ||
677-
!object.model.model ||
678-
!object.model.model.morphInstances) {
679-
return null;
680-
}
681-
var meshInstances = object.model.meshInstances;
682-
var morphInstance;
683-
for (var i = 0; i < meshInstances.length; ++i) {
684-
if (meshInstances[i].node.name === node.name) {
685-
morphInstance = meshInstances[i].morphInstance;
686-
break;
691+
var meshInstances = findMeshInstances(node);
692+
if (meshInstances) {
693+
var morphInstance;
694+
for (var i = 0; i < meshInstances.length; ++i) {
695+
if (meshInstances[i].node.name === node.name && meshInstances[i].morphInstance) {
696+
morphInstance = meshInstances[i].morphInstance;
697+
break;
698+
}
687699
}
688-
}
689-
if (!morphInstance) {
690-
return null;
691-
}
692-
var func = function (value) {
693-
for (var i = 0; i < value.length; ++i) {
694-
morphInstance.setWeight(i, value[i]);
700+
if (morphInstance) {
701+
var func = function (value) {
702+
for (var i = 0; i < value.length; ++i) {
703+
morphInstance.setWeight(i, value[i]);
704+
}
705+
};
706+
return new AnimTarget(func, 'vector', morphInstance.morph._targets.length);
695707
}
696-
};
697-
return new AnimTarget(func, 'vector', morphInstance.morph._targets.length);
708+
}
709+
710+
return null;
698711
},
699712
'materialTexture': function (node, textureName) {
700-
var object = node;
701-
while (object && object.constructor !== Entity) {
702-
object = object.parent;
703-
}
704-
if (!object ||
705-
!object.model ||
706-
!object.model.model) {
707-
return null;
708-
}
709-
var meshInstances = object.model.meshInstances;
710-
var meshInstance;
711-
for (var i = 0; i < meshInstances.length; ++i) {
712-
if (meshInstances[i].node.name === node.name) {
713-
meshInstance = meshInstances[i];
714-
break;
713+
var meshInstances = findMeshInstances(node);
714+
if (meshInstances) {
715+
var meshInstance;
716+
for (var i = 0; i < meshInstances.length; ++i) {
717+
if (meshInstances[i].node.name === node.name) {
718+
meshInstance = meshInstances[i];
719+
break;
720+
}
715721
}
716-
}
717-
if (!meshInstance) {
718-
return null;
719-
}
720-
var func = function (value) {
721-
var textureAsset = this.animComponent.system.app.assets.get(value[0]);
722-
if (textureAsset && textureAsset.resource && textureAsset.type === 'texture') {
723-
meshInstance.material[textureName] = textureAsset.resource;
724-
meshInstance.material.update();
722+
if (meshInstance) {
723+
var func = function (value) {
724+
var textureAsset = this.animComponent.system.app.assets.get(value[0]);
725+
if (textureAsset && textureAsset.resource && textureAsset.type === 'texture') {
726+
meshInstance.material[textureName] = textureAsset.resource;
727+
meshInstance.material.update();
728+
}
729+
}.bind(this);
730+
return new AnimTarget(func, 'vector', 1);
725731
}
726-
}.bind(this);
727-
return new AnimTarget(func, 'vector', 1);
732+
}
733+
734+
return null;
728735
}.bind(this)
729736
};
730737

src/asset/asset-reference.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* @param {object} [callbacks.load] - The function called when the asset loads load(propertyName, parent, asset).
1111
* @param {object} [callbacks.add] - The function called when the asset is added to the registry add(propertyName, parent, asset).
1212
* @param {object} [callbacks.remove] - The function called when the asset is remove from the registry remove(propertyName, parent, asset).
13+
* @param {object} [callbacks.unload] - The function called when the asset is unloaded unload(propertyName, parent, asset).
1314
* @param {object} [scope] - The scope to call the callbacks in
1415
* @property {number} id Get or set the asset id which this references. One of either id or url must be set to initialize an asset reference.
1516
* @property {string} url Get or set the asset url which this references. One of either id or url must be called to initialize an asset reference.
@@ -36,13 +37,15 @@ function AssetReference(propertyName, parent, registry, callbacks, scope) {
3637
this._onAssetLoad = callbacks.load;
3738
this._onAssetAdd = callbacks.add;
3839
this._onAssetRemove = callbacks.remove;
40+
this._onAssetUnload = callbacks.unload;
3941
}
4042

4143
AssetReference.prototype._bind = function () {
4244
if (this.id) {
4345
if (this._onAssetLoad) this._registry.on("load:" + this.id, this._onLoad, this);
4446
if (this._onAssetAdd) this._registry.once("add:" + this.id, this._onAdd, this);
4547
if (this._onAssetRemove) this._registry.on("remove:" + this.id, this._onRemove, this);
48+
if (this._onAssetUnload) this._registry.on("unload:" + this.id, this._onUnload, this);
4649
}
4750

4851
if (this.url) {
@@ -57,6 +60,7 @@ AssetReference.prototype._unbind = function () {
5760
if (this._onAssetLoad) this._registry.off('load:' + this.id, this._onLoad, this);
5861
if (this._onAssetAdd) this._registry.off('add:' + this.id, this._onAdd, this);
5962
if (this._onAssetRemove) this._registry.off('remove:' + this.id, this._onRemove, this);
63+
if (this._onAssetUnload) this._registry.off("unload:" + this.id, this._onUnload, this);
6064
}
6165
if (this.url) {
6266
if (this._onAssetLoad) this._registry.off('load:' + this.url, this._onLoad, this);
@@ -70,11 +74,17 @@ AssetReference.prototype._onLoad = function (asset) {
7074
};
7175

7276
AssetReference.prototype._onAdd = function (asset) {
77+
this.asset = asset;
7378
this._onAssetAdd.call(this._scope, this.propertyName, this.parent, asset);
7479
};
7580

7681
AssetReference.prototype._onRemove = function (asset) {
7782
this._onAssetRemove.call(this._scope, this.propertyName, this.parent, asset);
83+
this.asset = null;
84+
};
85+
86+
AssetReference.prototype._onUnload = function (asset) {
87+
this._onAssetUnload.call(this._scope, this.propertyName, this.parent, asset);
7888
};
7989

8090
Object.defineProperty(AssetReference.prototype, 'id', {

src/asset/asset.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var VARIANT_DEFAULT_PRIORITY = ['pvr', 'dxt', 'etc2', 'etc1', 'basis'];
4343
* filename: "filename.txt",
4444
* url: "/example/filename.txt"
4545
* };
46-
* @param {object} [data] - JSON object with additional data about the asset (e.g. for texture and model assets) or contains the asset data itself (e.g. in the case of materials)
46+
* @param {object} [data] - JSON object with additional data about the asset. (e.g. for texture and model assets) or contains the asset data itself (e.g. in the case of materials)
4747
* @param {object} [options] - The asset handler options. For container options see {@link pc.ContainerHandler}
4848
* @param {boolean} [options.crossOrigin] - For use with texture resources. For browser-supported image formats only, enable cross origin.
4949
* @example
@@ -61,7 +61,7 @@ var VARIANT_DEFAULT_PRIORITY = ['pvr', 'dxt', 'etc2', 'etc1', 'basis'];
6161
* @property {string} [file.hash] The MD5 hash of the resource file data and the Asset data field or null if hash was set (e.g from using {@link pc.AssetRegistry#loadFromUrl})
6262
* @property {ArrayBuffer} [file.contents] Optional file contents. This is faster than wrapping the data
6363
* in a (base64 encoded) blob. Currently only used by container assets.
64-
* @property {object} [data] Optional JSON data that contains either the complete resource data (e.g. in the case of a material) or additional data (e.g. in the case of a model it contains mappings from mesh to material)
64+
* @property {object} [data] Optional JSON data that contains either the complete resource data. (e.g. in the case of a material) or additional data (e.g. in the case of a model it contains mappings from mesh to material)
6565
* @property {object} [options] - Optional JSON data that contains the asset handler options.
6666
* @property {object} resource A reference to the resource when the asset is loaded. e.g. a {@link pc.Texture} or a {@link pc.Model}
6767
* @property {Array} resources A reference to the resources of the asset when it's loaded. An asset can hold more runtime resources than one e.g. cubemaps

src/framework/application.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import { HtmlHandler } from '../resources/html.js';
6262
import { JsonHandler } from '../resources/json.js';
6363
import { MaterialHandler } from '../resources/material.js';
6464
import { ModelHandler } from '../resources/model.js';
65+
import { RenderHandler } from '../resources/render.js';
6566
import { ResourceLoader } from '../resources/loader.js';
6667
import { SceneHandler } from '../resources/scene.js';
6768
import { SceneSettingsHandler } from '../resources/scene-settings.js';
@@ -99,6 +100,7 @@ import { LayoutChildComponentSystem } from './components/layout-child/system.js'
99100
import { LayoutGroupComponentSystem } from './components/layout-group/system.js';
100101
import { LightComponentSystem } from './components/light/system.js';
101102
import { ModelComponentSystem } from './components/model/system.js';
103+
import { RenderComponentSystem } from './components/render/system.js';
102104
import { ParticleSystemComponentSystem } from './components/particle-system/system.js';
103105
import { RigidBodyComponentSystem } from './components/rigid-body/system.js';
104106
import { ScreenComponentSystem } from './components/screen/system.js';
@@ -714,6 +716,7 @@ function Application(canvas, options) {
714716
this.loader.addHandler("animclip", new AnimClipHandler());
715717
this.loader.addHandler("animstategraph", new AnimStateGraphHandler());
716718
this.loader.addHandler("model", new ModelHandler(this.graphicsDevice, this.scene.defaultMaterial));
719+
this.loader.addHandler("render", new RenderHandler(this.assets));
717720
this.loader.addHandler("material", new MaterialHandler(this));
718721
this.loader.addHandler("texture", new TextureHandler(this.graphicsDevice, this.assets, this.loader));
719722
this.loader.addHandler("text", new TextHandler());
@@ -741,6 +744,7 @@ function Application(canvas, options) {
741744
this.systems.add(new AnimationComponentSystem(this));
742745
this.systems.add(new AnimComponentSystem(this));
743746
this.systems.add(new ModelComponentSystem(this));
747+
this.systems.add(new RenderComponentSystem(this));
744748
this.systems.add(new CameraComponentSystem(this));
745749
this.systems.add(new LightComponentSystem(this));
746750
if (script.legacy) {

src/framework/components/anim/component.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ Object.assign(AnimComponent.prototype, {
4646
data.layers = [];
4747

4848
var graph;
49-
var modelComponent = this.entity.model;
50-
if (modelComponent) {
51-
var m = modelComponent.model;
49+
if (this.entity.model) {
50+
var m = this.entity.model.model;
5251
if (m) {
5352
graph = m.getGraph();
5453
}
54+
} else {
55+
// animating hierarchy without model
56+
graph = this.entity;
5557
}
5658

5759
function addLayer(name, states, transitions, order) {

0 commit comments

Comments
 (0)