Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - AGP

#21
Support / Environment Mapping with Software
February 06, 2018, 06:40:35 PM
One of my ships is shiny. I have a vague memory of talking to you about environment mapping with the software renderer. I fully expected that the environment map would not work with the software renderer, but my expectation was that the diffuse map would be completely replaced by the environment map and that the environment map would be treated as diffuse. This is not so. Ambient map acts like the ambient map but the diffuse channel disappears. To that end, I tried writing the following method. But obviously, the result is that the ambient map is just colored by the diffuse. My question, then, is since the environment mapping is already performing as expected, would it be possible to just make the diffuse channel work with it?


     private void combineAmbientAndDiffuse() {
Texture tex = TextureManager.getInstance().getTexture("EnvironmentMap");
tex.add(TextureManager.getInstance().getTexture("Starfighter.png"), .5f);
     }
#22
Support / Drawing a Graphic on a Separate Thread
February 01, 2018, 03:35:33 AM
Hardware renderer in (lwjgl's frame) fullscreen throws a RuntimeException ("No OpenGL context found in the current thread."). I created a WorldProcessor with two threads as well as tried it the lwjgl way (GLContext.useContext()). Neither worked.
#23
Support / Interact2D
January 16, 2018, 08:38:03 PM
I'm trying to make a little level editor. Right now, all it will do is to allow you to position some enemies by clicking on the 3d map. I'm not very interested in the y coordinate, because they will place themselves relative to the floor's height). But the following code always places the enemiies in the same (marked) spot:
https://www.dropbox.com/s/r73iukqn0wdtcjs/LE.jpg?dl=0


     public void mouseClicked(MouseEvent e) {
Point p = e.getPoint();
SimpleVector p3d = Interact2D.reproject2D3DWS(camera, buffer, p.x, p.y);
System.out.println("p3d: "+p3d);
p3d.y = -2000f;
objects[numberOfObjects++] = Primitives.getCube(100f);
objects[numberOfObjects-1].build();
objects[numberOfObjects-1].translate(p3d);
theWorld.addObject(objects[numberOfObjects-1]);
     }
#24
If so, how do I wait for it? My app is failing to find a texture after it's been added to the TextureManager.
#25
Support / rotateMesh Bug
January 10, 2018, 03:16:28 PM
The following code doesn't crash with Object3D.rotateY(...) but crashes with a NullPointerException on Object3D.rotateMesh().


if (ship instanceof Blah) {
     ship.body.rotateY((float)Math.PI*.5f);
     ship.body.rotateMesh();
     ship.body.clearRotation();
}
#26
Support / Too Bright With Software Renderer
December 20, 2017, 06:52:49 AM
I even wrote the following (where "amount" refers to color intensity for all three colors):


int amount = 15;
float attenuation = 3.6f, dist = 1f;
theWorld.setAmbientLight(25, 25, 25);//-20
if (b.usesRenderer(IRenderer.RENDERER_OPENGL)) {
theWorld.setAmbientLight(125, 125, 125);//-20
     amount = 55;
     attenuation = 3600f;
     dist = 10f;
}
else Config.lightMul = 1;
#27
Support / Loader.loadOBJ Problem
October 31, 2017, 08:33:08 PM

System.out.println("\n\n\nWarcraft.loadObject: "+fileName +" Is the mtl null? "+(mtlFile==null));
System.out.println("Is loadOBJ(fileName, mtlFile) null? "+(Loader.loadOBJ(fileName, mtlFile, .5f)==null));


Produces:
Quote
Warcraft.loadObject: buildings\castle_construction0.obj Is the mtl null? false
Exception in thread "main" java.lang.NullPointerException
        at java.util.Hashtable.put(Unknown Source)
        at com.threed.jpct.Loader.loadOBJ(Loader.java:819)
        at com.threed.jpct.Loader.loadOBJ(Loader.java:508)
        at Warcraft.loadObject(Warcraft.java:250)
        at Worker.moveTowardsDest(Character.java:393)
        at Warcraft.loop(Warcraft.java:320)
        at Warcraft.<init>(Warcraft.java:163)
        at Warcraft.main(Warcraft.java:1058)

I've opened the file in Blender and it loads just fine.
#28
Support / Fog Of War Transparency With Software
October 12, 2017, 03:02:14 AM
I''m writing a strategy game and can't seem to properly paint a transparent PNG on my fog (so that its edges are rounded). The logic for the texture placement is sound and has been tested. But all I get is solid black.


if (!TextureManager.getInstance().containsTexture("fog-top")) {
     TextureManager.getInstance().addTexture("fog-top", new Texture("Assets"+File.separator+"fog-top.png", true));
     TextureManager.getInstance().addTexture("fog-left", new Texture("Assets"+File.separator+"fog-left.png", true));
     TextureManager.getInstance().addTexture("fog-right", new Texture("Assets"+File.separator+"fog-right.png", true));
     TextureManager.getInstance().addTexture("fog-bottom", new Texture("Assets"+File.separator+"fog-bottom.png", true));
}
#29
Is this a jpct error? If so, what is it? I'm using the software renderer here.
#30
Support / Polyline.setLineLength?
September 23, 2017, 01:12:44 AM
I'm writing the following for my son (sorry about the captured frame-rate). The thing about Polyline.update(...) is that it's expensive to always create a new array (I suppose that I could store it, then edit it but that's quirky), and it's inconvenient. Also, the following is the code that increases the length of my laser (deltaTime*10f breaks the numbers by being making them too large):


SimpleVector pos = bridge.getTransformedCenter();
pos.y -= 160f;
SimpleVector forward = bridge.getZAxis();
laserLength *= (1f+(deltaTime*6f));
laser.update(new SimpleVector[]{pos, pos.calcAdd(new SimpleVector(forward.x*laserLength, forward.y*laserLength, forward.z*laserLength))});


https://www.youtube.com/watch?v=ui6R1ZDcEqI
#31
Support / LWJGL 3+
September 19, 2017, 06:09:52 AM
I've found no AWTGLCanvas in my brief exploration of its docs. I have, however, found this: https://javadoc.lwjgl.org/org/lwjgl/system/jawt/JAWT.html It's kind of funny the notion of someone going, "do you know what Java needs? Malloc. I miss malloc." LOL

Anyway, is there any chance that you might implement your own AWTGLCanvas from that? At some point, you have to recognize the need to update (either to the newer LWJGL or otherwise to jOGL or a third--to me unknown--wrapper). Right?
#32
Bones / Scale Problem?
August 29, 2017, 10:04:27 PM
I have a class called Bone, as defined in the following code. It's used as a bridge between the JSON-serialized format I created and Bones.


class Bone {
    protected String name;
    protected SimpleVector position;
    protected Matrix transform;
    protected int index, parentIndex;
    public Bone(String name, SimpleVector position, Matrix transform, int index, int parentIndex) {
        this.name = name;
        this.position = position;
        this.transform = transform;
        this.index = index;
        this.parentIndex = parentIndex;
    }
    public boolean hasParent () {
        return this.parentIndex >= 0;
    }
    public String toString () {
        return this.name + ": " + this.position;
    }
}


When I print its values as follows, I get perfectly reasonable numbers (values ranging from -30 to +120).

System.out.println(newBone.toString() +": "+newBone.index);

But, after creating my AnimatedGroup, as follows, the values range between -Infinity to +Infinity, with NaNs thrown in there for good measure.


    public static AnimatedGroup loadGroup(JsonLoader jsonLoader) {
        MaxBonesClip[] clips = Importer.getMaxBonesClips(jsonLoader);
        MaxBonesImporter jImporter = new MaxBonesImporter(jsonLoader, clips);
        ArrayList<ArrayList> objects = jImporter.getList();
        ArrayList<Bone> bones = jImporter.getBones();
        ArrayList<ArrayList> objectsBonesReferences = jImporter.getBonesReferences(); // for all objects, respects the same order of objects
        Animated3D anObject = null;
        SimpleVector center = null;
        scaleBones(bones);
        invertBonesCoords(bones);
        Skeleton skeleton = Importer.makeSkeleton(bones);
        SkeletonPose pose = new SkeletonPose(skeleton);
        pose.updateTransforms();
       
        Animated3D[] list = new Animated3D[objects.size()];
        for (int i = 0; i < objects.size(); i++) {
            ArrayList<ArrayList> theObject = objects.get(i);
            if (bones == null || bones.size() <= 0) {
                Logger.log("Problem: no bones. Try loadObject(String) instead.");
                java.awt.Toolkit.getDefaultToolkit().beep();
                return null;
            }
            anObject = makeAnimated3D(pose, objectsBonesReferences.get(i), theObject, new File(jsonLoader.getMainFileName()).getParent());
            anObject.build();
            list[i] = anObject;
        }
        System.out.println("To test: "+bones.get(JSONFrame.BONE_INDEX_TO_TEST));
        AnimatedGroup asGroup = new AnimatedGroup(list);
        asGroup.setSkinClipSequence(getSkinClipSequence(jImporter, anObject.getSkeleton()));
        return asGroup;
    }
    private static Animated3D makeAnimated3D(SkeletonPose pose, ArrayList<BoneReference> boneRefs, ArrayList<ArrayList> theImportedObject, String absolutePath) {
        ArrayList<ArrayList> vertices = theImportedObject.get(0);
        ArrayList<String> diffuseAndNormal = theImportedObject.get(3);
        int verticesCount = vertices.size();
       
        //skeletonDebugger = new SkeletonDebugger(pose, 0f, 1f);
       
        float[][] weights = new float[verticesCount][Importer.MAX_JOINTS_PER_VERTEX];
        short[][] jointIndices = new short[verticesCount][Importer.MAX_JOINTS_PER_VERTEX];
        int[] verticesCounters = new int[verticesCount];
        for (int i = 0; i < verticesCount; i++) verticesCounters[i] = 0;
       
        for (BoneReference aBoneRef: boneRefs) {
            int vertexRef = aBoneRef.vertexIndexReference;
           
            int verticesCounter = verticesCounters[vertexRef];
            if (verticesCounter < Importer.MAX_JOINTS_PER_VERTEX) {
                weights[vertexRef][verticesCounter] = aBoneRef.vertexWeight;
                jointIndices[vertexRef][verticesCounter] = aBoneRef.boneIndexReference;
                verticesCounters[vertexRef]++;
            }
        }
        SkinData skin = new SkinData(weights, jointIndices);
        if (!TextureManager.getInstance().containsTexture(diffuseAndNormal.get(0)))
        TextureManager.getInstance().addTexture(diffuseAndNormal.get(0), new Texture(absolutePath +File.separator+diffuseAndNormal.get(0)));
       
        MeshData meshData = makeMeshData(theImportedObject);
        Animated3D anAnimated = new Animated3D(meshData, skin, pose);
        anAnimated.setTexture(diffuseAndNormal.get(0));
        return anAnimated;
    }


These prints produce NaNs, and the infinities:

        for (int h = 0; h < asGroup.getSize(); h++) {
            Animated3D temp = asGroup.get(h);
           
            Skeleton s = asGroup.get(h).getSkeletonPose().getSkeleton();

            for (int i = 0; i < s.getNumberOfJoints(); i++) {
                System.out.println(temp.getSkinClipSequence().getClip(0).getSkeleton().getJoint(i).getBindPose().toString());

                //temp.applySkeletonPose();
                //temp.animateSkin(frame, sequence);
                //temp.applyAnimation();
            }
        }
#33
Bones / SkeletonDebugger Auto-Scale Feature?
August 18, 2017, 10:19:15 PM
I've been stuck for weeks on what has to be the last stages of my file format. I load the whole thing into bones without a problem, but animating it is something else altogether. When I try to use the SkeletonDebugger, I get an "ERROR: Invalid scale!" message. When I animate it, the center of the object doesn't change but it disappears entirely. No further errors as the animation runs, but no visible object, even with culling set to false.

I can't figure this error out (especially since I can reimport the object back into 3ds max and succesfully play its animations). Would it be possible to add some logic such that SkeletonHelper would automatically rescale this invalid scale?
#34
Support / Shadows
August 14, 2017, 06:04:38 AM
Egon, I'd really like to solve the shadow-map movement issue in jpct. I've put out finishing a nice little RPG game for a couple of years because of it. The following shows the problem I get when I move the sun:

https://www.youtube.com/watch?v=Z3KdV7mqEHY
#35
Support / Wall Collision
August 12, 2017, 12:10:26 AM
I'm trying to use the following code. In this case, the walls and the floor are different entities. Collision with the floor is handled separately and works fine. When I do get a collision with the walls, which is not always, I get printouts like "Collided and not with ground. Direction: (-7.939828, -2.0494497) Return route: (5.188492, -2.2546387)." Why would I not at least get the reverse of my direction? How should I do this, instead?

In loop():

     wallCollision(MOVE_SPEED);
     camera.moveCamera(Camera.CAMERA_MOVEIN, MOVE_SPEED);



    private void wallCollision(float MOVE_SPEED) {
SimpleVector cameraZ = camera.getZAxis();
SimpleVector direction = new SimpleVector(cameraZ.x*MOVE_SPEED, cameraZ.y*MOVE_SPEED, cameraZ.z*MOVE_SPEED);
SimpleVector newDirection = collide(direction);
    }
     private SimpleVector collide(SimpleVector directionToHead) {
ground.setVisibility(false);
SimpleVector direction = theWorld.checkCollisionEllipsoid(camera.getPosition(), directionToHead, ELLIPSOID_RADIUS, 5);//.5f, 2f, .5f), 5
if (directionToHead.x != direction.x || directionToHead.z != direction.z) {
     float multiplier = 1f;
     direction.x*= multiplier;
     direction.z*= multiplier;
System.out.println("Collided and not with ground. Direction: ("+directionToHead.x +", "+directionToHead.z +") Return route: ("+direction.x +", "+direction.z +").");
Toolkit.getDefaultToolkit().beep();
     camera.moveCamera(direction, 1f);
}
ground.setVisibility(true);
return direction;
     }
#36
Support / Only thing rendered is the SkyBox
June 11, 2017, 02:11:43 AM
And even that won't turn with the camera. The screen is being redrawn, the accelerometer data is being updated, and so on and so forth. onDrawFrame calls a loopIteration() method that only rotatesCameraY by a given amount, then redraws the screen. But the SkyBox doesn't rotate. It's the weirdest thing, but it should be a known issue (something that I'm doing wrong that's already been done). Right?
#37
Support / Oculus VR SDK
June 06, 2017, 05:45:14 PM
Has anyone ever done an example using Android Studio and the Oculus VR SDK?
#38
Bones / My Format
May 25, 2017, 04:01:30 AM
Raft, I sent you and Egon a screenshot of my Max exporter. My format, which comes out of 3ds max fully JSON-serialized, comes with three types of animation: vertex animation for expressions, skin animation, and a third kind, which is vertex animations in place of skin animations. Now there's two reasons for the third kind: no need for a bone structure should I use the format in other platforms and, more urgently, because although I can import a model whose joints distort it intuitively, I have never been able to play a skin animation either in Bones or in Blender (or, for that matter, in a Java port of Animadead which I made). The only thing I'm exporting, having tried everything else, are the euler angles per joint per animation frame. I'm convinced that that's enough, but I can't get it to work. The weights all appear to be the same as they are in Max. I would like your help in fixing this (there's really no other reasonable way to export skinned models out of Max and into Bones anymore now that OgreMax is dead).
#39
Support / How to import vertex animations
May 09, 2017, 02:12:21 PM
As you know, Egon, I'm writing that JSON-serialized file format. Right now, I'm working on the vertex animations. I've stored the frames in a file. The current version of the method looks like the following. But the trouble now is that the only idea I have is to clone the only Mesh instance I have and distort it with a vertex controller. But that doesn't really seem right to me.


     public static Object3D loadVertexAnimated(String fileName) {
        NoBonesImporter jImporter = new NoBonesImporter();
        ArrayList<ArrayList> objects = jImporter.getList(fileName);
ArrayList<NoBoneAnimation> importedAnimations = jImporter.getAnimations(fileName);
Object3D[] list = Object3D[objects.size()];
for (int i = 0; i < objects.size(); i++) {
     ArrayList<ArrayList> theObject = objects.get(i);
     ArrayList<ArrayList> importedVertices = theObject.get(0);
             ArrayList<ArrayList> importedUVs = theObject.get(1);
             ArrayList<ArrayList> importedFaces = theObject.get(2);
             float[] coordinates = makeCoordinates(importedVertices);
             float[] uvs = makeUVs(importedUVs);
             int[] indices = makeIndices(importedFaces);
     Object3D anObject = new Object3D(coordinates, uvs, indices,0);
     list[i] = anObject;

        }

int numTriangles = importedVertices.size(), numFrames = importedAnimations.size();
for (i = 0; i < numFrames; i++) {
     tmp.clearObject();
     int frame = i;
     Object3D anObject = list[i];
     Mesh aMesh = anObject.getMesh();
     NoBoneAnimation anAnimation = animations.get(i);
     String name = anAnimation.name;
     int numFrames = anAnimation.frames.size();
     Animation animation = new Animation(numFrames);

     for (ArrayList<ArrayList> importedVertices: anAnimation.frames) {
// Create a new mesh with vertex controller?
SimpleVector[] vertices = SimpleVector[importedVertices.size()];
for (int j = 0; j < vertices.length; j++) {
      SimpleVector v = new SimpleVector(vert.get(0), vert.get(1), vert.get(2));
vertices[j] = v;
      }
animation.addKeyFrame(...);
     }
}
Object3D anObject = makeAnimated3D(pose, objectsBonesReferences.get(i), theObject);
     }

#40
Support / Rotation Towards 3D Point
March 07, 2017, 09:10:49 PM
The following isn't working. How come?


     public void rotateTowards(SimpleVector towards) {
SimpleVector directionVector = new SimpleVector(towards.x -model.getTransformedCenter().x, towards.y -model.getTransformedCenter().y, towards.z -model.getTransformedCenter().z).normalize();//WON'T WORK WITH OR WITHOUT NORMALIZE()
Matrix rotationMatrix = directionVector.getRotationMatrix();
if (this instanceof Worker)
     ((Worker)this).setRotationMatrix(rotationMatrix);
else model.setRotationMatrix(rotationMatrix);
     }