Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3508 Members - Latest Member: NevilleKemp

26. May 2012, 04:46:01 pm
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)java.lang.Error: no colors set
Pages: [1]
Print
Author Topic: java.lang.Error: no colors set  (Read 398 times)
ahealingman
Just dropped in

Offline Offline

Posts: 14


View Profile Email
« on: 08. February 2011, 12:23:09 pm »

I'm lost with this one and need help. I only have an hour or so between jobs to work on this and I've spent the last few days (hours) trying to track down the problem.

The full exception:
Exception in thread "main" java.lang.Error: no colors set
   at org.jagatoo.geometry.GeometryDataContainer.hasColorAlpha(GeometryDataContainer.java:92)
   at org.xith3d.scenegraph.Geometry.hasColorAlpha(Geometry.java:251)
   at org.xith3d.scenegraph.Morph.buildCompatibleGeometry(Morph.java:148)
   at org.xith3d.scenegraph.Morph.setGeometryArrays(Morph.java:96)
   at org.xith3d.scenegraph.Morph.<init>(Morph.java:353)

Obviously there are no colors set in the geometry but I'm using a texture so as far as I know colors shouldn't be required. So can textures be used with Morph or must I use the geometry colors?

I'm loading 5 models each having 6 shapes to simulate walking. (Easiest to do it this way since I'm already loading other models)
I detach them and create separate Morph objects with a new appearance.
The models load and display fine, the problem only appears in the Morph object and I'm copying the model geometry as is: ie: legGeo = model[a].getShape(0).getGeometry();


I don't use wavefront .mtl files since java3d only displayed one texture per obj file I've got into the habit of setting up textures separately, don't know if this might affect Morph or not. I can't easily test this because graphics I have on a windows machine and coding is done on a linux machine (linux graphics drivers don't work well with this system and crashes in blender) and my workspace only allows one machine to be available at a time.

The simple solution is probably to just create an array of colors but if I can't use textures then I'm going to have to re-work a lot of things
Logged
ahealingman
Just dropped in

Offline Offline

Posts: 14


View Profile Email
« Reply #1 on: 09. February 2011, 12:03:47 pm »

update: added a color array to the geometry and all seems to be well now. Doesn't seem to be right that setting colors is required but at least its working now.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #2 on: 09. February 2011, 06:19:53 pm »

Should be fixed now.
Logged
ahealingman
Just dropped in

Offline Offline

Posts: 14


View Profile Email
« Reply #3 on: 10. February 2011, 11:05:44 pm »

Thanks!
I seem to be unable to get Morph working properly though, at least with a model. It seems like it should work, no errors, but it doesn't.

I went back to basics and copied the morphpyramid2cube test into my code and modified my code to match it as closely as possible. Both the morph test and my code work when I get the geometry as in the test:
Code:
g[ 0 ] = new ColorPyramidUp();
g[ 1 ] = new ColorCube();
g[ 2 ] = new ColorPyramidDown();

But when I get the geometry from a model the morph object displays but doesn't morph.   

Code:

    try {
for ( int a = 0; a < walkingShapes; a++)
        {
    model[a] = ModelLoader.getInstance().loadModel(resLoc.getResource( MODEL_CREATURE_DIRECTORY + creatureName + "walking" + String.valueOf(a).trim() + DEFAULT_MODEL_EXTENSION ) );
}
catch blocks

legGeo[z] = model[z].getShape(0).getGeometry();
headGeo[z] = model[z].getShape(1).getGeometry();

         

The 'models' that are being used is just a cube with 8 vertices which should display the same shapes as in the morph test code. The only change I make is from where the geometry comes from and it stops morphing


I can post the actual code if you want but I'd have to clean it up first, otherwise you'd lose your mind trying to follow it (I don't delete any test code until the class is working so I know what I've already tried, out of almost 3000 lines about 100 or so are working code)
« Last Edit: 10. February 2011, 11:07:57 pm by ahealingman » Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #4 on: 11. February 2011, 10:15:55 am »

Unfortunately I don't think, I will have the time to check your test code. But feel free to post it. Maybe someone else find the time.

Marvin
Logged
ahealingman
Just dropped in

Offline Offline

Posts: 14


View Profile Email
« Reply #5 on: 12. February 2011, 10:41:11 am »

Honestly, I wasn't requesting that anybody look at my code. I learned my first programming language around the same time that key punch machines were being phased out, though I did cart around my share of punch cards. Granted, I've only coded with java for the past 12 years but its no different then the programming and countless scripting languages I've been required to learn over the years.

If I required anybody to look at my code I probably would have given up 33 years ago.

What I thought I had pointed out in my post was the fact that Morph doesn't work with Model. If my post was vague in this respect I am sorry.

Since time is such a valuable commodity I have taken the MorphPyramid2CubeTest class and modified it to load a model instead of a hard-coded class. I have copied the modified code below so that it can be copied and pasted if required. I have also included an .obj file for a basic cube.

When a model is used Morphing action stops. If this is normal then just say so and I'll figure another way to implement it.



The only change I made to the original class was to comment the following lines and add code to get three models from disk. Original code that is commented:
Code:
g[ 0 ] = new ColorPyramidUp();
g[ 1 ] = new ColorCube();
g[ 2 ] = new ColorPyramidDown();

Code that is added:
Code:
ResourceLocator resLoc = ResourceLocator.create( "resources/" );
resLoc.createAndAddTSL( "textures" );
for ( int a = 0; a < 3; a++) {
model[a] = ModelLoader.getInstance().loadModel(resLoc.getResource( "cubeModel" + String.valueOf(a).trim() + ".obj" ) );
g[ 0 ] = model[0].getShape(0).getGeometry();
g[ 1 ] = model[1].getShape(0).getGeometry();
g[ 2 ] = model[2].getShape(0).getGeometry();





Code:

package org.xith3d.test.render;

import java.io.IOException;
import java.net.MalformedURLException;

import org.jagatoo.input.InputSystem;
import org.jagatoo.input.devices.components.Key;
import org.jagatoo.input.events.KeyPressedEvent;
import org.jagatoo.util.errorhandling.IncorrectFormatException;
import org.jagatoo.util.errorhandling.ParsingException;
import org.openmali.FastMath;
import org.xith3d.base.Xith3DEnvironment;
import org.xith3d.loaders.models.Model;
import org.xith3d.loaders.models.ModelLoader;
import org.xith3d.loop.CanvasFPSListener;
import org.xith3d.loop.opscheduler.Animator;
import org.xith3d.render.Canvas3D;
import org.xith3d.render.RenderPass;
import org.xith3d.resources.ResourceLocator;
import org.xith3d.scenegraph.Appearance;
import org.xith3d.scenegraph.BranchGroup;
import org.xith3d.scenegraph.Geometry;
import org.xith3d.scenegraph.Morph;
import org.xith3d.scenegraph.PolygonAttributes;
import org.xith3d.scenegraph.QuadArray;
import org.xith3d.scenegraph.Shape3D;
import org.xith3d.scenegraph.Transform3D;
import org.xith3d.scenegraph.TransformGroup;
import org.xith3d.scenegraph.View.ProjectionPolicy;
import org.xith3d.schedops.movement.RotatableGroup;
import org.xith3d.schedops.movement.TransformationDirectives;
import org.xith3d.test.Xith3DTest;
import org.xith3d.test.util.TestUtils;
import org.xith3d.utility.commandline.BasicApplicationArguments;
import org.xith3d.utility.events.WindowClosingRenderLoopEnder;

@Xith3DTest.Description
(
    fulltext = {
                   "Simple Xith3D Morph Pyramid2Cube test"
               },
    authors = {
                  "Yuri Vl. Gushchin (aka YVG)"
              }
)
public class MorphPyramid2CubeTest extends Xith3DTest //InputAdapterRenderLoop
{
    private RenderPass renderPass;
    private Morph morph;
   
    private BranchGroup createSceneGraph( Animator animator )
{
        BranchGroup rootBranch = new BranchGroup();
       
        RotatableGroup testRotateYGroup = new RotatableGroup( new TransformationDirectives( 0f, 0.1f, 0f ) );
       
        // Make extra transfrom we may want to play with (scale etc.)
        TransformGroup scaleTransform = new TransformGroup();
        Transform3D t = new Transform3D();
        t.setIdentity();
        scaleTransform.setTransform( t );
        testRotateYGroup.addChild( scaleTransform );
       
// Create the transform group nodes for the 3 original objects
// and the morphed object.  Add them to the root of the
// branch graph.
TransformGroup objTrans[] = new TransformGroup[ 4 ];

for ( int i = 0; i < 4; i++ )
        {
            objTrans[ i ] = new TransformGroup();
            scaleTransform.addChild( objTrans[ i ] );
}

Transform3D tr = new Transform3D();
Transform3D rotY15 = new Transform3D();
rotY15.rotY( FastMath.toRad( 15f ) );

objTrans[ 0 ].getTransform( tr );
tr.setTranslation( -3.0f, 1.5f, 0f );
tr.mul( rotY15 );
objTrans[ 0 ].setTransform( tr );

objTrans[ 1 ].getTransform( tr );
tr.setTranslation( 0.0f, 1.5f, 0f );
tr.mul( rotY15 );
objTrans[ 1 ].setTransform( tr );

objTrans[ 2 ].getTransform( tr );
tr.setTranslation( 3.0f, 1.5f, 0f );
tr.mul( rotY15 );
objTrans[ 2 ].setTransform( tr );

objTrans[ 3 ].getTransform( tr );
tr.setTranslation( 0.0f, -2.0f, 0f );
tr.mul( rotY15 );
objTrans[ 3 ].setTransform( tr );

// Now create simple geometries.
// QuadArray[] g = new QuadArray[ 3 ];
Geometry[] g = new Geometry[ 3 ];
Shape3D[] shape = new Shape3D[ 3 ];
for ( int i = 0; i < 3; i++ )
        {
            g[ i ] = null;
            shape[ i ] = null;
}


Model model[] = new Model[3];

try {
ResourceLocator resLoc = ResourceLocator.create( "resources/" );
resLoc.createAndAddTSL( "textures" );
for ( int a = 0; a < 3; a++) {
model[a] = ModelLoader.getInstance().loadModel(resLoc.getResource( "cubeModel" + String.valueOf(a).trim() + ".obj" ) );
}
} catch (IncorrectFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParsingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

g[ 0 ] = model[0].getShape(0).getGeometry();
g[ 1 ] = model[1].getShape(0).getGeometry();
g[ 2 ] = model[2].getShape(0).getGeometry();










// g[ 0 ] = new ColorPyramidUp();
// g[ 1 ] = new ColorCube();
// g[ 2 ] = new ColorPyramidDown();

Appearance a = new Appearance();
a.setPolygonAttributes( new PolygonAttributes( PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE ) );

for ( int i = 0; i < 3; i++ )
        {
            shape[ i ] = new Shape3D( g[ i ], a );
            objTrans[ i ].addChild( shape[ i ] );
}

// Create a Morph node, and set the appearance and input geometry
// arrays.
morph = new Morph( g, a );
objTrans[ 3 ].addChild( morph );
       
        rootBranch.addChild( testRotateYGroup );
//        animator.addAnimatableObject( testRotateYGroup );
       
        return ( rootBranch );
}
   
    @Override
    public void onKeyPressed( KeyPressedEvent e, Key key )
    {
        switch ( key.getKeyID() )
        {
            case ESCAPE:
                this.end();
                break;
               
            case SPACE:
                // Change the projection policy
                if ( renderPass.getConfig().getProjectionPolicy() == ProjectionPolicy.PERSPECTIVE_PROJECTION )
                {
                    renderPass.getConfig().setProjectionPolicy( ProjectionPolicy.PARALLEL_PROJECTION );
                }
                else
                {
                    renderPass.getConfig().setProjectionPolicy( ProjectionPolicy.PERSPECTIVE_PROJECTION );
                }
                break;
        }
    }

    private double[] weights = { 1.0, 0.0, 0.0 };
   
    @Override
    protected void prepareNextFrame( long gameTime, long frameTime, TimingMode timingMode )
    {
        super.prepareNextFrame( gameTime, frameTime, timingMode );
       
        final long micros = timingMode.getMicroSeconds( gameTime );
       
        final double a = (double)(micros % 2500000L) / 2500000.0;
       
        if ( a < 0.25 )
        {
           
            weights[ 0 ] = (1.0 - (a - 0.0) * 4.0);
            weights[ 1 ] = ((a - 0.0) * 4.0);
            weights[ 2 ] = 0.0;
        }
        else if ( a < 0.5 )
        {

            weights[ 0 ] = 0.0;
            weights[ 1 ] = (1.0 - (a - 0.25) * 4.0);
            weights[ 2 ] = ((a - 0.25) * 4.0);
        }
        else if ( a < 0.75 )
        {

            weights[ 0 ] = 0.0;
            weights[ 1 ] = ((a - 0.5) * 4.0);
            weights[ 2 ] = (1.0 - (a - 0.5) * 4.0);
        }
        else
        {

            weights[ 0 ] = ((a - 0.75) * 4.0);
            weights[ 1 ] = (1.0 - (a - 0.75) * 4.0);
            weights[ 2 ] = 0.0;
        }
       
        morph.setWeights( weights );
       
    }
   
    public MorphPyramid2CubeTest( BasicApplicationArguments arguments ) throws Throwable
    {
        super( arguments.getMaxFPS() );
       
        Xith3DEnvironment env = new Xith3DEnvironment( 0f, 0f, 7f,
                                                       0f, 0f, 0f,
                                                       0f, 1f, 0f,
                                                       this
                                                     );
       
        ResourceLocator resLoc = TestUtils.createResourceLocator();
       
        resLoc.createAndAddTSL( "textures" );
       
        BranchGroup rootBranch = createSceneGraph( this.getAnimator() );
       
        this.renderPass = env.addPerspectiveBranch( rootBranch );
       
        Canvas3D canvas = createCanvas( arguments.getCanvasConstructionInfo(), getClass().getSimpleName() );
        env.addCanvas( canvas );
       
        canvas.addWindowClosingListener( new WindowClosingRenderLoopEnder( this ) );
        this.addFPSListener( new CanvasFPSListener( canvas ) );
       
        InputSystem.getInstance().registerNewKeyboardAndMouse( canvas.getPeer() );
       
        System.out.println( "Hit SPACE to toggle projection policy, or ESC to exit" );
    }

public static void main( String[] args ) throws Throwable
{
    MorphPyramid2CubeTest test = new MorphPyramid2CubeTest( parseCommandLine( args ) );
   
    test.begin();
}
}

class ColorCube extends QuadArray
{
private static final float[] verts =
    {
    // front face
     1.0f, -1.0f,  1.0f,
     1.0f,  1.0f,  1.0f,
    -1.0f,  1.0f,  1.0f,
    -1.0f, -1.0f,  1.0f,
    // back face
    -1.0f, -1.0f, -1.0f,
    -1.0f,  1.0f, -1.0f,
     1.0f,  1.0f, -1.0f,
     1.0f, -1.0f, -1.0f,
    // right face
     1.0f, -1.0f, -1.0f,
     1.0f,  1.0f, -1.0f,
     1.0f,  1.0f,  1.0f,
     1.0f, -1.0f,  1.0f,
    // left face
    -1.0f, -1.0f,  1.0f,
    -1.0f,  1.0f,  1.0f,
    -1.0f,  1.0f, -1.0f,
    -1.0f, -1.0f, -1.0f,
    // top face
     1.0f,  1.0f,  1.0f,
     1.0f,  1.0f, -1.0f,
    -1.0f,  1.0f, -1.0f,
    -1.0f,  1.0f,  1.0f,
    // bottom face
    -1.0f, -1.0f,  1.0f,
    -1.0f, -1.0f, -1.0f,
     1.0f, -1.0f, -1.0f,
     1.0f, -1.0f,  1.0f,
};

private static final float[] colors =
    {
    // front face (red)
    1.0f, 0.0f, 0.0f,
    1.0f, 0.0f, 0.0f,
    1.0f, 0.0f, 0.0f,
    1.0f, 0.0f, 0.0f,
    // back face (green)
    0.0f, 1.0f, 0.0f,
    0.0f, 1.0f, 0.0f,
    0.0f, 1.0f, 0.0f,
    0.0f, 1.0f, 0.0f,
    // right face (blue)
    0.0f, 0.0f, 1.0f,
    0.0f, 0.0f, 1.0f,
    0.0f, 0.0f, 1.0f,
    0.0f, 0.0f, 1.0f,
    // left face (yellow)
    1.0f, 1.0f, 0.0f,
    1.0f, 1.0f, 0.0f,
    1.0f, 1.0f, 0.0f,
    1.0f, 1.0f, 0.0f,
    // top face (magenta)
    1.0f, 0.0f, 1.0f,
    1.0f, 0.0f, 1.0f,
    1.0f, 0.0f, 1.0f,
    1.0f, 0.0f, 1.0f,
    // bottom face (cyan)
    0.0f, 1.0f, 1.0f,
    0.0f, 1.0f, 1.0f,
    0.0f, 1.0f, 1.0f,
    0.0f, 1.0f, 1.0f,
};

ColorCube()
    {
    super( 24 );
   
    setCoordinates( 0, verts );
    setColors( 0, 3, colors );
}
}

class ColorPyramidDown extends QuadArray
{
private static final float[] verts =
    {
    // front face
     0.0f, -1.0f,  0.0f,
     1.0f,  1.0f,  1.0f,
    -1.0f,  1.0f,  1.0f,
     0.0f, -1.0f,  0.0f,
    // back face
     0.0f, -1.0f, 0.0f,
    -1.0f,  1.0f, -1.0f,
     1.0f,  1.0f, -1.0f,
     0.0f, -1.0f, 0.0f,
    // right face
     0.0f, -1.0f, 0.0f,
     1.0f,  1.0f, -1.0f,
     1.0f,  1.0f,  1.0f,
     0.0f, -1.0f,  0.0f,
    // left face
     0.0f, -1.0f,  0.0f,
    -1.0f,  1.0f,  1.0f,
    -1.0f,  1.0f, -1.0f,
     0.0f, -1.0f, 0.0f,
    // top face
     1.0f,  1.0f,  1.0f,
     1.0f,  1.0f, -1.0f,
    -1.0f,  1.0f, -1.0f,
    -1.0f,  1.0f,  1.0f,
    // bottom face
     0.0f, -1.0f,  0.0f,
     0.0f, -1.0f,  0.0f,
     0.0f, -1.0f, 0.0f,
     0.0f, -1.0f, 0.0f,
};

private static final float[] colors =
    {
    // front face (green)
    0.0f, 1.0f, 0.0f,
    0.0f, 1.0f, 0.0f,
    0.0f, 1.0f, 0.0f,
    0.0f, 1.0f, 0.0f,
    // back face (red)
    1.0f, 0.0f, 0.0f,
    1.0f, 0.0f, 0.0f,
    1.0f, 0.0f, 0.0f,
    1.0f, 0.0f, 0.0f,
    // right face (yellow)
    1.0f, 1.0f, 0.0f,
    1.0f, 1.0f, 0.0f,
    1.0f, 1.0f, 0.0f,
    1.0f, 1.0f, 0.0f,
    // left face (magenta)
    1.0f, 0.0f, 1.0f,
    1.0f, 0.0f, 1.0f,
    1.0f, 0.0f, 1.0f,
    1.0f, 0.0f, 1.0f,
    // top face  (blue)
    0.0f, 0.0f, 1.0f,
    0.0f, 0.0f, 1.0f,
    0.0f, 0.0f, 1.0f,
    0.0f, 0.0f, 1.0f,
    // bottom face (cyan)
    0.0f, 1.0f, 1.0f,
    0.0f, 1.0f, 1.0f,
    0.0f, 1.0f, 1.0f,
    0.0f, 1.0f, 1.0f,
};

    ColorPyramidDown()
    {
        super( 24 );
       
        setCoordinates( 0, verts );
        setColors( 0, 3, colors );
}
}

class ColorPyramidUp extends QuadArray
{
    private static final float[] verts =
    {
        // front face
         1.0f, -1.0f,  1.0f,
         0.0f,  1.0f,  0.0f,
         0.0f,  1.0f,  0.0f,
        -1.0f, -1.0f,  1.0f,
        // back face
        -1.0f, -1.0f, -1.0f,
         0.0f,  1.0f, 0.0f,
         0.0f,  1.0f, 0.0f,
         1.0f, -1.0f, -1.0f,
        // right face
         1.0f, -1.0f, -1.0f,
         0.0f,  1.0f,  0.0f,
         0.0f,  1.0f,  0.0f,
         1.0f, -1.0f,  1.0f,
        // left face
        -1.0f, -1.0f,  1.0f,
         0.0f,  1.0f,  0.0f,
         0.0f,  1.0f,  0.0f,
        -1.0f, -1.0f, -1.0f,
        // top face
         0.0f,  1.0f,  0.0f,
         0.0f,  1.0f,  0.0f,
         0.0f,  1.0f,  0.0f,
         0.0f,  1.0f,  0.0f,
        // bottom face
        -1.0f, -1.0f,  1.0f,
        -1.0f, -1.0f, -1.0f,
         1.0f, -1.0f, -1.0f,
         1.0f, -1.0f,  1.0f,
    };
   
private static final float[] colors =
    {
    // front face (cyan)
    0.0f, 1.0f, 1.0f,
    0.0f, 1.0f, 1.0f,
    0.0f, 1.0f, 1.0f,
    0.0f, 1.0f, 1.0f,
    // back face (magenta)
    1.0f, 0.0f, 1.0f,
    1.0f, 0.0f, 1.0f,
    1.0f, 0.0f, 1.0f,
    1.0f, 0.0f, 1.0f,
    // right face (yellow)
    1.0f, 1.0f, 0.0f,
    1.0f, 1.0f, 0.0f,
    1.0f, 1.0f, 0.0f,
    1.0f, 1.0f, 0.0f,
    // left face (blue)
    0.0f, 0.0f, 1.0f,
    0.0f, 0.0f, 1.0f,
    0.0f, 0.0f, 1.0f,
    0.0f, 0.0f, 1.0f,
    // top face (green)
    0.0f, 1.0f, 0.0f,
    0.0f, 1.0f, 0.0f,
    0.0f, 1.0f, 0.0f,
    0.0f, 1.0f, 0.0f,
    // bottom face (red)
    1.0f, 0.0f, 0.0f,
    1.0f, 0.0f, 0.0f,
    1.0f, 0.0f, 0.0f,
    1.0f, 0.0f, 0.0f,
};

ColorPyramidUp()
    {
    super( 24 );
   
    setCoordinates( 0, verts );
    setColors( 0, 3, colors );
}
}


Code:
# Blender3D v249 OBJ File:
# www.blender3d.org
mtllib man-walking0.mtl
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
usemtl Material
s off
f 1 2 3 4
f 5 8 7 6
f 1 5 6 2
f 2 6 7 3
f 3 7 8 4
f 5 1 4 8

« Last Edit: 12. February 2011, 10:44:35 am by ahealingman » Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic