Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

animations not always loaded and certain animations loaded incorrectly #1

Closed
Kakrain opened this issue Dec 18, 2014 · 17 comments
Closed

Comments

@Kakrain
Copy link

Kakrain commented Dec 18, 2014

Hello, first of all thank you a lot at doing this.. without your help i would have to spend a lot of time programming a loader for meshes and worrying about the animations and stuff, you helped me a lot in saving me time.

the first error is as shown in the next image:

sin tituloh

sometimes the animations fail to be loaded, when i extract the animations (skeleton animations) the size of the array is 0; in this image it failed twice, sometimes it fails one and sometimes it doesnt fail at all.
this is the second error:

halberdiererror
sometimes the orientation of the meshes aren't correct, they are not the same as shown in the editor, i had to sort of change the orientation in a strange way in the editor in order to make it look good on the game.

@kdrnic
Copy link
Owner

kdrnic commented Dec 20, 2014

Hi, would you mind sharing your mesh, loading code and Misfit Model 3D version? Then I will have some pointers to look at this issue.

@Kakrain
Copy link
Author

Kakrain commented Dec 21, 2014

sure... i think its not really a great code but nvm here it is:

first this is Bodymatico.js
has 4 objects:
-BodyMatico that loads a mesh and then is able to create any number of objects of type:
-Body that has a mesh and its animations and some functions to call those anims
-WeaponMatico that loads a weapon and its able to generate any number of objects of type:
-Weapon that has the mesh of the weapon and some functions that has the weapon logic... here it is:

function BodyMatico(url,skin,_scene){
var scene=_scene;
var model = new MM3DModel();
var busy=false;
var skinBoxes = null;
var ready=false;
var scale=1;

this.terminate=function(){
    delete model;
    delete busy;
    delete skinBoxes;
    delete ready;
    delete scale;
}
var setScale=function(s){
    scale=s;
}
this.isReady=function(){
    return ready;
}
model.OnLoad = function()
{
    ready=true;
}
model.Load(url);
this.generate=function(){
    geometry = model.GetGeometry();//crea un mesh;
    geometry.computeFaceNormals();
    geometry.computeBoundingSphere();
    texture = THREE.ImageUtils.loadTexture(skin);
    texture.needsUpdate = true;
    var material = new THREE.MeshLambertMaterial({map: texture, skinning: true});
    skinAnimations = model.GetSkeletalAnimations();
    var mesh = new THREE.SkinnedMesh(geometry, material);
    mesh.scale.set(scale,scale,scale);

    var animations=[];
    var boxes=[];
    for(var i = 0; i < mesh.skeleton.bones.length; i++)
    {
        var b = new THREE.Object3D();
        b.applyMatrix(mesh.skeleton.bones[i].matrix);
        b.matrix.copy(mesh.skeleton.bones[i].matrix);
        boxes[i] = b;
    }
    for(var i = 0; i < mesh.skeleton.bones.length; i++)
    {
        if(mesh.skeleton.bones[i].parent instanceof THREE.SkinnedMesh) mesh.add(boxes[i]);
        else
        {
            for(var j = 0; j < mesh.skeleton.bones.length; j++)
            {
                if(mesh.skeleton.bones[i].parent == mesh.skeleton.bones[j])
                {
                    boxes[j].add(boxes[i]);
                }
            }
        }
    }
    for(var i = 0; i < skinAnimations.length; i++) {animations[i] = new THREE.Animation(mesh, skinAnimations[i]);}
        animations[3].loop=false;
        animations[4].loop=false;
        animations[5].loop=false;
        animations[6].loop=false;
        animations[7].loop=false;
        animations[8].loop=false;

        animations[9].loop=false;
        animations[10].loop=false;

        animations[3].timeScale = 2.5;
        animations[4].timeScale = 2.5;
        animations[5].timeScale = 2.5;
        animations[6].timeScale = 4;
        animations[9].timeScale = 2.5;
        animations[10].timeScale = 4;

        animations[1].play();
    mesh.castShadow = true;
    mesh.receiveShadow = true;
    scene.add(mesh);
    return (new Body(mesh,animations,boxes));
}

}
function WeaponMatico(url,skin){
var ready=false;
var m = new MM3DModel();
var g=null;
var mat=null;
var scale=0.3;
this.setScale=function(s){
scale=s;
}
m.OnLoad = function()
{
ready=true;
}
m.Load(url);
this.generate=function(){
var t = THREE.ImageUtils.loadTexture(skin);
t.needsUpdate = true;
mat = new THREE.MeshLambertMaterial({map: t})
var weapon = new THREE.Mesh(m.GetGeometry(), mat);
weapon.scale.set(scale,scale,scale);
return weapon;
}
this.isReady=function(){
return ready;
}
}
function Body(_mesh,_animations,_skinboxes){
var mesh=_mesh;
var animations=_animations;
var skinboxes=_skinboxes;

this.terminate=function(scene){
scene.remove(mesh);
delete mesh;
delete animations;
delete skinboxes;
}
this.update=function(){

for(var i = 0; i < skinboxes.length; i++)
    {
        skinboxes[i].position.copy(mesh.skeleton.bones[i].position);
        skinboxes[i].rotation.copy(mesh.skeleton.bones[i].rotation);
    }

}
this.addWeapon=function(mesh){
skinboxes[13].add(mesh);
}
this.getMesh=function(){
return mesh;
}
this.getBoxes=function(){
return skinboxes;
}
this.calmarse=function(){
var foco=animations[0].isPlaying;
if(foco){animations[0].stop()}
animations[2].stop();
animations[4].play();
var worker = new Worker('js/worker.js');
worker.postMessage("marco");//usar al worker
worker.addEventListener('message', function(e) {
if(animations[4].isPlaying){
worker.postMessage("marco");
}else{
animations[1].play();
worker.terminate();
if(foco){animations[0].play();}
}
}, false);
}
this.alarmarse=function(){
var foco=animations[0].isPlaying;
if(foco){animations[0].stop()}
animations[1].stop();
animations[3].play();
var worker = new Worker('js/worker.js');
worker.postMessage("marco");//usar al worker
worker.addEventListener('message', function(e) {
if(animations[3].isPlaying){
worker.postMessage("marco");
}else{
animations[2].play();
worker.terminate();
if(foco){animations[0].play();}
}
}, false);
}
this.atacar=function(){
animations[1].stop();
animations[2].stop();
if(Math.random()>=0.5){
this.swing();
}else{
this.stab();
}
}
this.swing=function(){
animations[5].play();
var worker = new Worker('js/worker.js');
worker.postMessage("marco");//usar al worker
worker.addEventListener('message', function(e) {
if(animations[5].isPlaying){
worker.postMessage("marco");
}else{
animations[6].play();
worker.terminate();
}
}, false);
}
this.stab=function(){
animations[9].play();
var worker = new Worker('js/worker.js');
worker.postMessage("marco");//usar al worker
worker.addEventListener('message', function(e) {
if(animations[9].isPlaying){
worker.postMessage("marco");
}else{
animations[10].play();
worker.terminate();
}
}, false);
}
this.block=function(){
animations[1].stop();
animations[2].stop();
animations[8].play();
}
this.gostop=function(){
if(animations[0].isPlaying){
animations[0].stop();
return;
}
animations[0].play();
}
this.walk=function(){
animations[0].play();
}
this.stopwalk=function(){
animations[0].stop();
}
}

in the main file i load the halberdier using this function:

function loadHalberdiers(){
var worker = new Worker('js/worker.js');
worker.postMessage("marco");//usar al worker
worker.addEventListener('message', function(e) {
if(!halberdierMatico.isReady()&&!halberdMatico.isReady()){
$.notify("marco");
worker.postMessage("marco");
}else{
try{
//$.notify("bastardo no es null");//no pasa por aqui cuando falla...tal ves al de arriba cambia de puntero

                    worker.terminate();
                    weapon=new Weapon(30,10,1);
                    enemy=new Actor (halberdierMatico.generate(),scene,ambiente,allies,enemies);
                    enemies[enemies.length]=enemy;
                    enemy.setPosition(60,-50,60);

                    enemy.setAzimut(Math.PI/2);
                    enemy.addArma(weapon,halberdMatico.generate());
                    /*enemy.addPatrolPosition(new THREE.Vector3(10,0,10));
                    enemy.addPatrolPosition(new THREE.Vector3(-10,0,10));
                    enemy.addPatrolPosition(new THREE.Vector3(10,0,-10));*/
                    ally=new Actor (halberdierMatico.generate(),scene,ambiente,enemies,allies);
                    allies[allies.length]=ally;
                    ally.setPosition(-60,-50,60);
                    ally.addArma(weapon.clone(),halberdMatico.generate());
                }catch(err){
                    loadHalberdiers();
                    $.notify("erro una vez");
                    }
                //$.notify("esta cargado correcto: "+halberdierMatico.loadedCorrectly());

              }
            }, false);
        }

and finally the workers i use have just simply this code:
self.addEventListener('message', function(e) {
self.postMessage("polo");
}, false);

@Kakrain
Copy link
Author

Kakrain commented Dec 21, 2014

im not sure how to send the meshes.... i will change its extensions to png... when u download them please change them back to mm3D

halberdmodel

halberdiermodel

ronaldo

halberdier

the misfit modeller version is 1.2.4

@Kakrain
Copy link
Author

Kakrain commented Dec 21, 2014

oops sorry, this is the texture for the halberd (the weapon)
halberd

@Kakrain
Copy link
Author

Kakrain commented Dec 21, 2014

also..... i am not able to fit it correctly in the ground, but that may be my error, hopefully if this 2 issues are solved then i may be able to do it right... btw si hablas español mejor hablemos ambos español ñ_ñ

@kdrnic
Copy link
Owner

kdrnic commented Dec 22, 2014

Perhaps you could simply zip your working directory and send me it over DropBox or Google Drive? That would be more convenient to me.

Also, can you name which animations are shown differently from the modeler?

I don't speak Spanish, only Portuguese.

Looking over your code, you seem not to have used "this." with some variables I think you intended to be object members, so you have probably created some globals.Of course it is not that that is causing the issues, but I thought I should comment.

@Kakrain
Copy link
Author

Kakrain commented Dec 23, 2014

can i have a gmail or hotmail in order to send u the project in zip?

@kdrnic
Copy link
Owner

kdrnic commented Dec 23, 2014

Can't you just upload to Google Drive or Dropbox and paste the link here?

@Kakrain
Copy link
Author

Kakrain commented Dec 23, 2014

@Kakrain
Copy link
Author

Kakrain commented Dec 23, 2014

sorry, i didn't know how to;
also, we are using node.js to load the page, perhaps if u dont have a server or something like that it may not load

@kdrnic
Copy link
Owner

kdrnic commented Dec 23, 2014

I've got the RAR, I will look over tis issue after the holidays.

Again, can you list which animations have this display issue? There are many animations in your model.

@Kakrain
Copy link
Author

Kakrain commented Dec 24, 2014

thank you n_n
the animations are:
moving: (see the left hand)
idle: (the left hand again)
idleAttack (both hands and right arm)
block and blockstab (arms are totally crazy)
same with stab and stabup (the last one is totally crazy in the editor but fine in the game)

@Kakrain
Copy link
Author

Kakrain commented Jan 14, 2015

@kdrnic
Copy link
Owner

kdrnic commented Feb 13, 2015

Hi,
sorry for not looking at this issue sooner. I took an entire month to reply to you, such is inexcusable.

On close inspection, I found a few small issues with my code, that have been corrected. The current revision no longer has such issues.

However, I found an issue with three.js, that is an obstacle to the loading of this format.
I opened the following issue where the problem is explained mrdoob/three.js#6065 and I hope it will be soon fixed. This issue puts the usability of my code in doubt until it is fixed on the three.js side. I will update this repository's readme to note this limitation.

@kdrnic
Copy link
Owner

kdrnic commented Feb 13, 2015

Oh, meanwhile you could use the morph target animations.

@Kakrain
Copy link
Author

Kakrain commented Feb 14, 2015

its okay.. i understand the hard life of a programmer ñ_ñ sometimes there are things that are solver easily, others there is something that makes us stop... nowadays im using blender importer/exporter from an example with a rigged marine... im still troubling with making animations though ñ_ñ (i dont like blender) but i wish that you could solve the problems with your mm3d js because it let me load the mesh just once and then if i need more just clone the geometries... thats something the blender example dont let me, oh also mm3d has a simpler way of animating a mesh

@kdrnic kdrnic closed this as completed in fe53abb Jul 22, 2015
@kdrnic
Copy link
Owner

kdrnic commented Jul 22, 2015

This issue was finally fixed by adding a function to the code that uses interpolation to patch loaded keyframes.

The underlying limitation of three.js remains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants