@@ -50,9 +50,6 @@ void Start () {
5050 audioSource = FindObjectOfType < AudioSource > ( ) ;
5151 }
5252
53- // Load the initial motion.
54- LoadMotion ( Application . streamingAssetsPath + "/default_bvh.txt" ) ;
55-
5653 // Load the initial model.
5754 string [ ] cmdArgs = System . Environment . GetCommandLineArgs ( ) ;
5855 if ( cmdArgs . Length > 1 )
@@ -63,8 +60,11 @@ void Start () {
6360 LoadModel ( Application . streamingAssetsPath + "/default_vrm.vrm" ) ;
6461 }
6562
63+ // Load the initial motion.
64+ LoadMotion ( Application . streamingAssetsPath + "/default_bvh.txt" ) ;
65+
6666 // Initialize window manager
67- windowController = FindObjectOfType < WindowController > ( ) ;
67+ windowController = FindObjectOfType < WindowController > ( ) ;
6868 if ( windowController )
6969 {
7070 // Add a file drop handler.
@@ -172,27 +172,44 @@ private void SetMotion(HumanPoseTransfer motion, HumanPoseTransfer model, VRMMet
172172 /// <param name="path"></param>
173173 private void LoadMotion ( string path )
174174 {
175- ImporterContext context = new ImporterContext
176- {
177- Path = path
178- } ;
175+ if ( ! File . Exists ( path ) ) return ;
176+
177+ GameObject newMotionObject = null ;
179178
180179 try
181180 {
181+ BvhImporterContext context = new BvhImporterContext ( ) ;
182+ //Debug.Log("Loading motion : " + path);
182183
183- BvhImporter . Import ( context ) ;
184- motion = context . Root . GetComponent < HumanPoseTransfer > ( ) ;
185- motion . GetComponent < Renderer > ( ) . enabled = false ;
184+ context . Parse ( path ) ;
185+ context . Load ( ) ;
186+ newMotionObject = context . Root ;
187+
188+ // Hide the motion model
189+ Renderer renderer = newMotionObject . GetComponent < Renderer > ( ) ;
190+ if ( renderer )
191+ {
192+ renderer . enabled = false ;
193+ }
186194
187- SetMotion ( motion , model , meta ) ;
188195 } catch ( Exception ex )
189196 {
190197 if ( uiController ) uiController . SetWarning ( "Motion load failed." ) ;
198+ Debug . LogError ( "Failed loading " + path ) ;
191199 Debug . LogError ( ex ) ;
192200 return ;
193201 }
194- finally
202+
203+ if ( newMotionObject )
195204 {
205+ if ( motion )
206+ {
207+ GameObject . Destroy ( motion . gameObject ) ;
208+ }
209+
210+ motion = newMotionObject . GetComponent < HumanPoseTransfer > ( ) ;
211+ SetMotion ( motion , model , meta ) ;
212+
196213 // Play loaded audio if available
197214 if ( audioSource && audioSource . clip && audioSource . clip . loadState == AudioDataLoadState . Loaded )
198215 {
@@ -209,35 +226,36 @@ private void LoadMotion(string path)
209226 private void LoadModel ( string path )
210227 {
211228 if ( ! File . Exists ( path ) ) return ;
212-
213- GameObject newModel = null ;
229+ GameObject newModelObject = null ;
214230
215231 try
216232 {
217233 // Load from a VRM file.
218- byte [ ] bytes = File . ReadAllBytes ( path ) ;
219- context = new VRMImporterContext ( UniGLTF . UnityPath . FromFullpath ( path ) ) ;
220- context . ParseGlb ( bytes ) ;
221- VRMImporter . LoadFromBytes ( context ) ;
234+ context = new VRMImporterContext ( ) ;
235+ //Debug.Log("Loading model : " + path);
222236
223- newModel = context . Root ;
237+ context . Load ( path ) ;
238+ newModelObject = context . Root ;
224239 meta = context . ReadMeta ( ) ;
240+
241+ context . ShowMeshes ( ) ;
225242 }
226243 catch ( Exception ex )
227244 {
228245 if ( uiController ) uiController . SetWarning ( "Model load failed." ) ;
246+ Debug . LogError ( "Failed loading " + path ) ;
229247 Debug . LogError ( ex ) ;
230248 return ;
231249 }
232250
233- if ( model )
251+ if ( newModelObject )
234252 {
235- GameObject . Destroy ( model . gameObject ) ;
236- }
253+ if ( model )
254+ {
255+ GameObject . Destroy ( model . gameObject ) ;
256+ }
237257
238- if ( newModel )
239- {
240- model = newModel . AddComponent < HumanPoseTransfer > ( ) ;
258+ model = newModelObject . AddComponent < HumanPoseTransfer > ( ) ;
241259 SetMotion ( motion , model , meta ) ;
242260
243261 model . gameObject . AddComponent < CharacterBehaviour > ( ) ;
0 commit comments