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

MainOpenfl Not Working #40

Open
dresch86 opened this issue Aug 26, 2015 · 25 comments
Open

MainOpenfl Not Working #40

dresch86 opened this issue Aug 26, 2015 · 25 comments

Comments

@dresch86
Copy link

I re-cloned the repository and tried to build the OpenFL examples. The MainOpenfl class is not working for me. It builds but all I get is gray screen if I try to load the BasicScene sample. No error messages. The MainLime builds and works fine though.

Here is my project.xml for OpenFl builds:

   <meta title="BabylonHx_Openfl" package="com.babylonhx" version="1.0.0" company="Krtolica Vujadin" />
   <app main="MainOpenfl" file="BabylonHx_OpenFL" path="bin_openfl" />

   <window require-shaders="true" hardware="true" depth-buffer="true" stencil-buffer="true" antialiasing="0" />

    <source path="src" />

    <haxelib name="lime" />
    <haxelib name="openfl" />
    <haxelib name="actuate" />
    <haxelib name="poly2trihx" />

    <assets path="assets" exclude="*.svg" />
    <icon path="assets/lime.svg" />

</project>
@dresch86
Copy link
Author

I'm having same trouble getting the MainNME to work. It builds without errors and enters the BasicScene class but does not display any meshes.

Update: I got it working by un-commenting this line:

new Layer("background", "assets/img/graygrad.jpg", scene, true);)

I had commented it out because I did not want to go on a hunt for the image. Didn't think it would matter. What is a Layer and why is it necessary?

@vujadin
Copy link
Owner

vujadin commented Sep 7, 2015

OpenFL build is broken with the latest OpenFL release. Still haven't figured out why. About layer, it that particular case it behaves as a 'background image' (it shows stratched png image of radial gradient)

@dresch86
Copy link
Author

dresch86 commented Sep 7, 2015

I've got the OpenFL build working with the latest release with following code.

package;

import lime.app.Application;
import lime.Assets;
import lime.ui.KeyCode;
import lime.ui.KeyModifier;
import lime.graphics.RenderContext;
import lime.ui.Touch;
import lime.ui.Window;

import openfl.display.Stage;
import openfl.display.Sprite;
import openfl.events.Event;

import com.babylonhx.Engine;
import com.babylonhx.Scene;

/**

...
@author Krtolica Vujadin */

class MainOpenfl extends Application {
private var _stage:Stage;
private var _babylonSprite:Sprite;

private var scene:Scene;
private var engine:Engine;

public function new() {
    super();
}

public override function onWindowCreate(window:Window):Void {       
    _babylonSprite = new Sprite();
    window.stage = new Stage(window, 0xFFFFFFFF);
    window.stage.addChild(_babylonSprite);
    engine = new Engine(_babylonSprite, false); 
    scene = new Scene(engine);

    //new samples.BasicScene(scene);
    //new samples.BasicElements(scene);
    //new samples.CandleLight(scene);
    //new samples.RotationAndScaling(scene);
    //new samples.Materials(scene);
    //new samples.Lights(scene);
    //new samples.BumpMap(scene);
    //new samples.Animations(scene);
    //new samples.Collisions(scene);
    //new samples.Intersections(scene);
    //new samples.EasingFunctions(scene);
    //new samples.ProceduralTextures(scene);
    //new samples.MeshImport(scene);
    //new samples.LoadScene(scene);
    new samples.BasicScene(scene);
    //new samples.Fog(scene);
    //new samples.DisplacementMap(scene);
    //new samples.Environment(scene);
    //new samples.LensFlares(scene);
    //new samples.PhysicsCannon(scene);
    //new samples.Physics(scene);
    //new samples.Physics2(scene);
    //new samples.Physics_Pyramid(scene);
    //new samples.PhysicsSimple(scene);
    //new samples.PhysicsCar(scene);
    //new samples.PhysicsNew(scene);
    //new samples.PolygonMesh1(scene);
    //new samples.PolygonMesh2(scene);
    //new samples.PolygonMesh3(scene);
    //new samples.CustomRenderTarget(scene);
    //new samples.Lines(scene);
    //new samples.Lines2(scene);
    //new samples.Bones(scene);     
    //new samples.Shadows(scene);
    //new samples.Shadows2(scene);
    //new samples.HeightMap(scene);
    //new samples.LoadObjFile(scene);
    //new samples.LoadStlFile(scene);
    //new samples.LoadPlyFile(scene);
    //new samples.LOD(scene);
    //new samples.Instances(scene);
    //new samples.Instances2(scene);
    //new samples.Fresnel(scene);       
    //new samples.VolumetricLights(scene);
    //new samples.CellShading(scene);
    //new samples.Particles(scene);
    //new samples.Particles2(scene);
    //new samples.Particles3(scene);
    //new samples.Extrusion(scene);
    //new samples.Sprites(scene);
    //new samples.PostprocessBloom(scene);
    //new samples.PostprocessRefraction(scene);
    //new samples.PostprocessConvolution(scene);
    //new samples.GodRays(scene);
    //new samples.DepthOfField(scene);
    //new samples.Actions(scene);
    //new samples.Picking(scene);       
    //new samples.Octree(scene);
    //new samples.SSAO(scene);                      
    //new samples.Decals(scene);
    //new samples.InstancedBones(scene);                
    //new samples.AdvancedShadows(scene);
    //new samples.Ribbons(scene);
    //new samples.RibbonTest2(scene);
    //new samples.SoftShadows(scene);       
    //new samples.BabylonHxWebsiteScene(scene);
    //new samples.Water(scene);

    engine.width = this.window.width;
    engine.height = this.window.height;
}

override function onMouseDown(window:Window, x:Float, y:Float, button:Int) {
    for(f in Engine.mouseDown) {
        f(x, y, button);
    }
}

override function onMouseUp(window:Window, x:Float, y:Float, button:Int) {
    for(f in Engine.mouseUp) {
        f();
    }
}

override function onMouseMove(window:Window, x:Float, y:Float) {
    for(f in Engine.mouseMove) {
        f(x, y);
    }
}

override function onMouseWheel(window:Window, deltaX:Float, deltaY:Float) {
    for (f in Engine.mouseWheel) {
        f(deltaY / 2);
    }
}

override function onTouchStart(touch:Touch) {
    for (f in Engine.touchDown) {
        f(touch.x, touch.y, touch.id);
    }
}

override function onTouchEnd(touch:Touch) {
    for (f in Engine.touchUp) {
        f(touch.x, touch.y, touch.id);
    }
}

override function onTouchMove(touch:Touch) {
    for (f in Engine.touchMove) {
        f(touch.x, touch.y, touch.id);
    }
}

override function onKeyUp(window:Window, keycode:Int, modifier:KeyModifier) {
    for(f in Engine.keyUp) {
        f(keycode);
    }
}

override function onKeyDown(window:Window, keycode:Int, modifier:KeyModifier) {
    for(f in Engine.keyDown) {
        f(keycode);
    }
}

override public function onWindowResize(window:Window, width:Int, height:Int) {
    engine.width = this.window.width;
    engine.height = this.window.height;
}

override function update(deltaTime:Int) {
    if(engine != null) 
    engine._renderLoop();       
}

}

I think the problems was how the Stage got added and how the main Sprite was added to the Stage. I worked off of the new MainLime and incorporated the OpenFl components.

@vujadin
Copy link
Owner

vujadin commented Sep 8, 2015

This doesn't work for me (win). Do you work on Mac ?

@dresch86
Copy link
Author

dresch86 commented Sep 8, 2015

Hmm....I thought I was full updated, but I guess the haxelib repo wasn't updated until yesterday. When I ran haxelib update openfl today I got the following:

C:/HaxeToolkit/haxe/lib/openfl/3,3,3/openfl/_internal/renderer/cairo/CairoTextField.hx:6: characters 7-40 : Type not found : lime.graphics.cairo.CairoFontFace

And others if I commented out the import of CairoFontFace. Seems bad form to me to remove something without a replacement. I guess we have to wait now....

@vujadin
Copy link
Owner

vujadin commented Sep 8, 2015

You need to update lime too.

@dresch86
Copy link
Author

dresch86 commented Sep 8, 2015

Thought I did that too.....Haxe needs a better package manager. Anyway, now I am getting this which is BHx related:

com/babylonhx/tools/Tools.hx:527: lines 527-530 : img : lime.graphics.Image -> Bool should be Bool
com/babylonhx/tools/Tools.hx:527: lines 527-530 : For optional function argument 'useCache'

@vujadin
Copy link
Owner

vujadin commented Sep 8, 2015

yes, lime has switched to futures/promises... huge update is coming in a
few minutes

On Tue, Sep 8, 2015 at 8:44 PM, primesoftware notifications@github.com
wrote:

Thought I did that too.....Haxe needs a better package manager. Anyway,
now I am getting this which is BHx related:

com/babylonhx/tools/Tools.hx:527: lines 527-530 : img :
lime.graphics.Image -> Bool should be Bool
com/babylonhx/tools/Tools.hx:527: lines 527-530 : For optional function
argument 'useCache'


Reply to this email directly or view it on GitHub
#40 (comment).

@dresch86
Copy link
Author

dresch86 commented Sep 8, 2015

Coming from a Java background and having used the Netty project I cringe when I hear Futures/Promises......I understand the benefit but they really are a nuisance.

@vujadin
Copy link
Owner

vujadin commented Sep 8, 2015

I've just pushed a huge update. it should build now

@dresch86
Copy link
Author

dresch86 commented Sep 8, 2015

Close....the Lime errors are gone but now this:

com/babylonhx/physics/plugins/OimoPlugin.hx:380: characters 92-116 : Array has no field toArray
com/babylonhx/physics/plugins/OimoPlugin.hx:389: characters 72-96 : Array has no field toArray

@vujadin
Copy link
Owner

vujadin commented Sep 8, 2015

ok, OimoHx is updated also now :)

@dresch86
Copy link
Author

dresch86 commented Sep 8, 2015

com/babylonhx/physics/plugins/OimoPlugin.hx:380: characters 92-108 : For function argument 'array'
com/babylonhx/physics/plugins/OimoPlugin.hx:389: characters 5-88 : haxe.ds.Vector should be Array

Change those lines to ....#else body.getMatrix().toArray() #end;

@vujadin
Copy link
Owner

vujadin commented Sep 8, 2015

that's strange ... you've updated oimohx lib in the root of the project ?
what is your target ?

On Tue, Sep 8, 2015 at 10:20 PM, primesoftware notifications@github.com
wrote:

com/babylonhx/physics/plugins/OimoPlugin.hx:380: characters 92-108 : For
function argument 'array'
com/babylonhx/physics/plugins/OimoPlugin.hx:389: characters 5-88 :
haxe.ds.Vector should be Array


Reply to this email directly or view it on GitHub
#40 (comment).

@dresch86
Copy link
Author

dresch86 commented Sep 8, 2015

Yes all updated. I'm targeting windows,

@ramsestom
Copy link

Hi vujadin

Just to say that I performed a git update of BabylonHx and OimoHx (so as an haxelib upgrade of lime and openfl) and I have the same result as with previous version. My pure openfl project works fine when compiling for html5 target (with the -Ddom compilation flag) but still render as a black screen (after a few milliseconds scene display) for cpp (windows or android) targets. So does the new update only fix lime futures/promises changes or was it also supposed to fix the "shader" problem? If not, could you restore your "invisible mesh dirty hack" in the Scene class and push it to the repository to see if it can temporarily fix the problem? Thanks

Bytheway, looking at my android debug log, just after the message
I/trace (23473): Engine.hx:164: BabylonHx - Cross-Platform 3D Engine | 2015 | www.babylonhx.com
I found this message:
W/Adreno200-ES20(23473): <qgl2DrvAPI_glTexParameterfv:737>: GL_INVALID_ENUM
Don't know if it is related to the black screen issue but, if so, maybe it could help you trace the origin of the issue

@vujadin
Copy link
Owner

vujadin commented Sep 9, 2015

ramsestom,

"invisible mesh dirty hack" wont work here as Lime build works fine. This is OpenFL problem.

Can you get a call stack from that debug log ? If we can track down the function which makes this call, we could maybe solve this issue.

@ramsestom
Copy link

I don't see why the "invisible mesh dirty hack" won't work as the issue is the same as with lime previously (first frame displayed then black screen). If it was fixing it for lime, why wouldn't it for openfl? Maybee it wouldn't but we can't know before having tried. So I think it is worth trying...

As for the android debug log. I can't know the function that make the bad call from it unfortunately. As the error probably appear in a native opengl call, this error is not traced back to the haxe function that called it. The only way I see to try to identify the problematic function would be to put some trace flags at different points of the scene class and see between which trace calls the issue appears...
Here is the complete log report for my babylonopenfl process anyway:

I/ActivityManager( 590): Start proc com.sample.babylonopenfl for activity com.sample.babylonopenfl/.MainActivity: pid=31577 uid=10086 gids={3003, 3004, 1029}
E/Trace (31577): error opening trace file: No such file or directory (2)
D/ActivityThread(31577): setTargetHeapUtilization:0.25
D/ActivityThread(31577): setTargetHeapIdealFree:8388608
D/ActivityThread(31577): setTargetHeapConcurrentStart:2097152
V/SDL (31577): Device: a9
V/SDL (31577): Model: S500
V/SDL (31577): onCreate(): null
I/OpenAL_SLES(31577): alc_opensles_init
V/SDL (31577): onResume()
I/Adreno200-EGL(31577): <qeglDrvAPI_eglInitialize:269>: EGL 1.4 QUALCOMM build: (Merge)
I/Adreno200-EGL(31577): Build Date: 01/03/13 Thu
I/Adreno200-EGL(31577): Local Branch:
I/Adreno200-EGL(31577): Remote Branch:
I/Adreno200-EGL(31577): Local Patches:
I/Adreno200-EGL(31577): Reconstruct Branch:
V/SDL (31577): surfaceCreated()
V/SDL (31577): surfaceChanged()
V/SDL (31577): pixel format RGB_565
V/SDL (31577): Window size: 720x1184
I/SDL (31577): SDL_Android_Init()
I/SDL (31577): SDL_Android_Init() finished!
I/haxe plugin(31577): Got Load Proc 5f768250
I/haxe plugin(31577): Got Load Proc 5f768250
I/haxe plugin(31577): Got Load Proc 5f768250
I/haxe plugin(31577): Got Load Proc 5f768250
I/OpenAL_SLES(31577): opensles_open_playback pDevice=0x5bf25008, deviceName=(null)
I/OpenAL_SLES(31577): alc_opensles_probe DEVICE_PROBE
V/SDL (31577): onWindowFocusChanged(): true
I/ActivityManager( 590): Displayed com.sample.babylonopenfl/.MainActivity: +410ms
I/OpenAL_SLES(31577): opensles_reset_playback pDevice=0x5bf25008
I/OpenAL_SLES(31577): bits=16, channels=2, samples=1024, size=4096, freq=44100
I/OpenAL_SLES(31577): create audio player
I/OpenAL_SLES(31577): playback_function started
I/OpenAL (31577): _SC_NPROCESSORS_ONLN=2
I/SDL/APP (31577): Added joystick Android Accelerometer with device_id -2147483648
I/trace (31577): Engine.hx:166: BabylonHx - Cross-Platform 3D Engine | 2015 | www.babylonhx.com
W/Adreno200-ES20(31577): <__load_uniform_int:325>: GL_INVALID_OPERATION

The issue reported with the latest babylonHx version is different that the one I had with the previous one (GL_INVALID_OPERATION vs GL_INVALID_ENUM with the previous one) but the symptom is still the same (first frame display then black screen)

@ramsestom
Copy link

I just tested with the CSGDemo rather than with the BumpMap sample with openfl and it is working! So the "one frame" issue on android seems to occur only on some specific cases... Is it because CSGDemo use mesh? if so, the "invisible mesh hack" should work to make all samples to work with openfl...

@vujadin
Copy link
Owner

vujadin commented Sep 9, 2015

Strange enough CSGDemo shows only one frame for me :)
Few other samples work fine though. But ...
I was able to show sprite on top of 3D content only on one sample (with water material). While the sprite renders fine, FPS counter in it renders as a black box (no font visible) so this means that text can't be used.
So I don't see the benefit of using OpenFL instead of Lime (in which everything works fine) if we can't use OpenFL 2D API to render 2D content on top of 3D scene properly.
Anyway, BasicElements is an example of "invisible mesh hack". It contains Line mesh. What you need is simplest possible Line mesh like this:
var lines = Mesh.CreateLines("MyInvisibleMeshHack", [
new Vector3(-1, 0, 0),
new Vector3(1, 0, 0)
], scene);

then you set its alpha to 0.01 and in your update() function set its position in front of your camera, so it never leaves frustum. And that's it.

@ramsestom
Copy link

Well I haven't the black box issue when rendering text in front of a babylon scene with openfl (with CSGDemo sample). However, my text is rendered as if looking in a miror and at wrong position on android.

For example the following code:
var scoreField:TextField = new TextField();
scoreField.width = 30;
scoreField.x = 30;
scoreField.y = 30;
scoreField.text = "Test";
addChild(scoreField);

render as:

screenshot_2015-09-09-21-26-45 1

whereas on html5:

image

But the advantage of using openfl rather than lime is that you can use any framework built on top of openfl (I use haxeflixel and my final goal is to be able to use BabylonHx in my haxeflixel games to render 3D).

@dresch86
Copy link
Author

@ramsestom How did you get "test" to show at all? Do you have a complete example? I've been trying to get a TextField to show, but no luck. I know it is there because I see the cursor change, but I don't see the text. I've also had some success in including StablexUI, but it also won't show if I add Babylon to the stage. Without rendering Babylon it works just fine.

BabylonJS has a GUI called cGUI. I'm considering working on a project to get a GUI interface for BabylonHx. It would be an asset to the community.

@ramsestom
Copy link

Yes. My example test class was pretty simple actually:

package;

import openfl.display.Sprite;
import openfl.display.Bitmap;
import openfl.display.BitmapData;
import openfl.Assets;

import com.babylonhx.Engine;
import com.babylonhx.Scene;

class Main extends Sprite {

private var scene:Scene;
private var engine:Engine;
private var _babylonSprite:Sprite;

public function new () {

    super ();

    _babylonSprite = new Sprite();
    engine = new Engine(this, false);   
    scene = new Scene(engine);
    engine.width = stage.stageWidth;
    engine.height = stage.stageHeight;
    new CSGDemo(scene); 
    addChild(_babylonSprite);

    var scoreField:TextField = new TextField();
    scoreField.width = 30;
    scoreField.x = 30;
    scoreField.y = 30;
    scoreField.text = "Test";
    addChild(scoreField);


    #if lime
        trace("Lime");
    #end
    #if openfl
        trace("OpenFL");
    #end
    #if legacy
        trace("Legacy");
    #end

}

}

with CSGDemo beeing the CSGDemo class from the babylonHX example project

And I am using openfl next as I couldn't make babylonHx to work with openfl legacy :(

@jobs-git
Copy link

@ramsestom This is not working for me :(

@mightymarcus
Copy link

BabylonJS has a GUI called cGUI. I'm considering working on a project to get a GUI interface for >>BabylonHx. It would be an asset to the community.

Something happended since then? I'm looking for a way to simply show Text over the 3D Scene, this would be fundamental for a game I think ;)

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

5 participants