Login Action Required

The NinevehGL Forum uses a new concept of "socialized forum" or as we like to say "Tweet Forum".


Here is the deal:
  1. No new registration is required. Just sign in with your Twitter account and authorize the NinevehGL Forum.
  2. Once you’re in, you'll be able to "Follow a Thread", that means every time that thread receive a new post or update you'll receive a mention on your twitter.
  3. Besides, you can enable "Auto Share", then every new post and/or thread you make will be tweeted on your timeline. (By default, auto-share is enabled only for your threads)

Forum Rules:

1. We understand human comunication can become "hot" sometimes. So some insults and bad words ARE allowed. Just don't push too much being an asshole all the time.

2. SPAMMERS are not allowed. There are penalties for this kind of user and they can be banned forever.

3. You can report other users, if you judge necessary. An user reported many times by many people can also be banned forever. However you can also receive penalties for report deliberately for no apparent reason.

If there is a similar thread title, make sure the other one doesn't already have the answer you're looking for.

This forum uses the BBCode (Bulletin Board Code), here are some instructions:

Bold: [b]text[/b]
Italic: [i]text[/i]
Underline: [u]text[/u]

Code: [code]text[/code]
Quote:
[quote=@username]text[/quote]
[quote]text[/quote]

List:
[ul] [*]item [/ul]
[ol] [*]item [/ol]

URL:
[url]http://url.com[/url]
[url=http://url.com]text[/url]

Image:
[img]http://imageurl.com[/img]

Embed (videos, code, 3D):
[embed]http://url.com[/embed]

Welcome to the NinevehGL's world!
NinevehGL is a 3D engine forged with pure Obj-C.
Welcome to the
Forum!
Hello, Guest.

Your current vote:

You can change your vote many times. But it's still one single vote.

Download 3D objects from the internet
Vote this thread:


@Khaled_Mahmoud1

Posts: 16

NGLNewbie

Tue, Jul 31 2012


Dear all,

I'd like to let my application download 3D objects that uploaded on my own server
i can download it with no problems
but the problem now is how can i initialize all objects in ViewDidLoad() method
and assign each object to it's own marker
I tried to make an array to hold this objects ... but it doesn't work
0% like this - 0/0

@dineybomfim

Posts: 571

NGLAdmin

Tue, Jul 31 2012


In response to: @Khaled_Mahmoud1



Hello buddy,



Sorry, but again are missing information to us help you.



What exactly are you facing? What error? what code you're using for?

Are you downloading your files to the Libraries folder? Or Documents?

Are you changing the NinevehGL Global Path?



0% like this - 0/0

@Khaled_Mahmoud1

Posts: 16

NGLNewbie

Tue, Jul 31 2012


In response to: @dineybomfim

I downloaded my objects to the document folder
my problem is i don't know the idea to load more than one object dynamically and display it based on the marker
I tried to load all objects in array but nothing done and no error message

do you have any another idea to do this scenario?
0% like this - 0/0

@dineybomfim

Posts: 571

NGLAdmin

Tue, Jul 31 2012


In response to: @Khaled_Mahmoud1

Hey buddy,

Sorry to insist... but you're not giving us any information...
You're saying abstract things... "I have an array and try to load all, but nothing happen"...

What that means? What're you doing?
Where is your code? Are you creating one NGLMesh for each file? Are you trying to load all objects at once?
Show us what you're doing. Otherwise we'll keep in the dark and can't help you.

The Marker is Qualcomm related, you can track many marks with one single .xml and .dat file. So you compare "trackable->getName()" to know which marker is being tracked. Take the Qualcomm AR examples and study them, see how they track multiple markers.
0% like this - 0/0

@Khaled_Mahmoud1

Posts: 16

NGLNewbie

Wed, Aug 1 2012


In response to: @dineybomfim

Hi,
Sorry for confusion
I will describe my problem in more details

What i need to do ? :

1- upload 3d objects to my own server and let my application to download it in update scenario and put it in document directory .... this step working very well

2- Load all 3d objects in ViewDidLoad() method ... so i write this lines of code in ViewDidLoad() method

int arraylength = 0;
NGLMesh *objfile;
NSDictionary *settings;
settings = [NSDictionary dictionaryWithObjectsAndKeys:
kNGLMeshCentralizeYes, kNGLMeshKeyCentralize,
@"3.0", kNGLMeshKeyNormalize,
nil];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSFileManager *manager = [NSFileManager defaultManager];

NSArray *fileList = [manager directoryContentsAtPath:documentsDirectory];
for (NSString *s in fileList)
{
if ([s hasSuffix:@".obj"])
{
arraylength ;
}
}
objectarray = [NSMutableArray arrayWithCapacity:arraylength]; // Property Defined in .h file
for (NSString *s in fileList)
{
objfile = [[NGLMesh alloc] initWithFile:s settings:settings delegate:self];
objfile.x = -0.0f;
objfile.y = -0.0f;
objfile.z = -0.0f;
[objectarray addObject:objfile];
_camera = [[NGLCamera alloc] initWithMeshes:_dragon, objfile, nil];
}
The problem here is: when i run my application i see the progress bar doesn't move and do nothing

3- Display each object based on the marker, but how can i access my array drawView() method

I hope that the description is clear
0% like this - 0/0

@dineybomfim

Posts: 571

NGLAdmin

Wed, Aug 1 2012


In response to: @Khaled_Mahmoud1

OK buddy,

Now you gave us something.
Here is the problems:

A - (Optimization): The lines

for (NSString *s in fileList)


Are redundant, you can make one single loop. BTW, don't create instances inside the loop instructions, this is not following the Best Practices for C programming. Besides, using camel case and describe the variables is always better than variables like "a", "b", "c1", "dh", etc... You should keep the variable declaration outside the loops. Like this:

NSString *fileName;
for (fileName in fileList)


B - (Problem): By your "objectarray" behavior, you're using ARC, right? However this is why I hate ARC. You're trying to use the same behavior for the _camera, which is strong instance because you defined it inside the class definition. So you're reallocating the NGLCamera in there and you're producing leaks, because class instances will be released once at the dealloc.

Using ARC is sucks, every instance should be in fact a property with the instruction "strong" or "weak" and you should call "self.property = [[Something alloc] init];". Actually ARC prefer much more lines than this.... It prefer this:

Something *sInstance = [[Something alloc] init];
self.property = sInstance;


In this situation ARC is 100% sure. It'll release the "sInstance" and retain the "self.property", which will be released only when you set a new property or when the dealloc was called.

So, talking specifically about your code, you're creating one camera for each object you have in folder and placing both meshes (dragon and your mesh) inside it. You should allocate the camera ONCE, outside the loop. The best place to initialize the camera is inside the "viewDidLoad", "loadView" or inside the "init". Then you just add or remove meshes from your camera during the application life time.

C - (Problem): The NGLMeshDelegate will track each mesh individually, not all of loading meshes. You should create a routine to sum the loading percentages for all of your objects. When you set all the loading meshes' delegates to "self" you're instructing NinevehGL that each mesh will individually report its progress to "self". So you'll receive things like:

Mesh 1: progress 5%.
Mesh 2: progress 3%.
Mesh 4: progress 6%.
Mesh 3: progress 5%.
Mesh 5: progress 2%.
...

It's your responsible to take the average of all this loading. Remember that NinevehGL loading is per file and there is no group loading yet.


D - (Tip): To track multiple targets, if you've generated the .dat file correctly on the Qualcomm website, your code, inside the "drawView" method will be like this:


myMesh1.visible = NO;
myMesh2.visible = NO;
myMesh3.visible = NO;
myMesh4.visible = NO;

if (!strcmp(trackable->getName(), "trackable1"))
{
myMesh1.visible = YES;
}
else if (!strcmp(trackable->getName(), "trackable2"))
{
myMesh2.visible = YES;
}
else if (!strcmp(trackable->getName(), "trackable3"))
{
myMesh3.visible = YES;
}
else if (!strcmp(trackable->getName(), "trackable4"))
{
myMesh4.visible = YES;
}

[_camera drawCamera];


Hope this helps you now.
0% like this - 0/0

@Khaled_Mahmoud1

Posts: 16

NGLNewbie

Wed, Aug 1 2012


In response to: @dineybomfim

Hi,

First, thank you for your quick reply

A- Thank you for your advice

B- mmmm I don't know well the concept of ARC, so i can't understand well why it's cause a problem for me

C- According to your words: if i'v more than 10 or 20 mesh it will take a long time to load in ViewDidLoad() method.right?

D- I can't call the objects directly because it is placed in the array and i shouldn't know the actual number of the objects, so i need to do something like this

for(int i=0; i<arraylength; i )
{
// for each object in the array
[objectarray objectAtIndex:i].visible = NO;
}

if (!strcmp(trackable->getName(), "trackable1"))
{
[objectarray objectAtIndex:1].visible = YES;
}
else if (!strcmp(trackable->getName(), "trackable2"))
{
[objectarray objectAtIndex:1].visible = YES;
}

but the problem is i don't know how can i do it


Out of all previous problems i thought for another solution but i don't know if it is good or not
my new solution is load each object by button action, so i created this method that take the obj name ... and remove the code from ViewDidLoad() method

- (void) loadobjects:(NSString *)objname
{
// Loading the dragon.
NSDictionary *settings;
settings = [NSDictionary dictionaryWithObjectsAndKeys:
kNGLMeshCentralizeYes, kNGLMeshKeyCentralize,
@"1.0", kNGLMeshKeyNormalize,
nil];
_dragon = [[NGLMesh alloc] initWithFile:@"Red Dragon.dae" settings:settings delegate:nil];

// Loading the mountain.
settings = [NSDictionary dictionaryWithObjectsAndKeys:
kNGLMeshCentralizeYes, kNGLMeshKeyCentralize,
@"3.0", kNGLMeshKeyNormalize,
nil];
_mountain = [[NGLMesh alloc] initWithFile:objname settings:settings delegate:self];
_mountain.x = -0.0f;
_mountain.y = -0.0f;
_mountain.z = -0.0f;

// Initializing the camera.
_camera = [[NGLCamera alloc] initWithMeshes:_dragon, _mountain, nil];

// Starts the debug monitor.
[[NGLDebug debugMonitor] startWithView:(NGLView *)self.view];
}

and create a button for each marker that do this action

[self loadobjects:@"myfile.obj"]

the problem now is: when i click on the button i see this alert "Application initialisation failed."
this means that it can't load the object.right?

In your opinion what's the best way to load the 3D objects dynamically ... by load all in ViewDidLoad() method OR by load each object by button action?!!

Thank you again for your help
0% like this - 0/0

@dineybomfim

Posts: 571

NGLAdmin

Wed, Aug 1 2012


In response to: @Khaled_Mahmoud1

A -

B - I'll talk more about it below.

C -

D - Again, this will not get work. The following lines will produce leaks, even with ARC:
"_dragon = [[NGLMesh alloc] initWithFile:@"Red Dragon.dae" settings:settings delegate:nil];"
"_mountain = [[NGLMesh alloc] initWithFile:objname settings:settings delegate:self];"
"_camera = [[NGLCamera alloc] initWithMeshes:_dragon, _mountain, nil];"

Because they are all instance variables.

Look, this is why I don't agree at all with ARC, new programmers will not be used to Memory management and this can generate a lot of issues, leaks, errors and other problems. ARC is not smart, so it'll understand things at this way:


  • A variable is defined inside a function or method: "This is a weak reference and it must be released inside this function/method scope".
  • A variable is define as class variable, inside the @interface: "This is a strong reference and it'll not be released until the full deallocation of this class".


So, if "_dragon", "_mountain" and "_camera" are all class variables, you can't allocate them many times. This is the worst thing about ARC that Apple doesn't tells us... using ARC will require you write more code!

Following the ARC guidelines, you MUST create a property (@property) and mark it as "strong" or "weak" instead of creating class variables. This is the only way to instruct the compiler to do the right thing with the memory. However @property is in fact a method call and this is much more expensive than using a class variable.

Back to your problem: using ARC, "_dragon", "_mountain" and "_camera" must become properties and you'll call them as "self.dragon" instead of "_dragon".

This help you to understand ARC?

---

About the trackable... well, so in your case the best solution is using a Dictionary, instead of an Array.

Create a NSMutableDictionary property and initialize it inside the "init" method. Then, when loading your meshes, add the meshes into the dictionary with exactly the same key as your trackable (defined in the Qualcomm site), for example:

[_myDictionary setObject:myMesh forKey:@"trackable1"];

Now inside the "drawView" method you could:

NSString *key = [NSString stringWithUTF8String:trackable->getName()];
NGLMesh *workingMesh = [_myDictionary objectForKey:key];
workingMesh.visible = YES;

[_camera drawCamera];

workingMesh.visible = NO;


If you still with many doubts about ARC, iOS and NinevehGL I suggest you to send us your project via email (in Contact you can find it) and we can send you more code based on your project.
0% like this - 0/0

@Khaled_Mahmoud1

Posts: 16

NGLNewbie

Fri, Aug 3 2012


In response to: @dineybomfim

Hi,

Thank you for your help

I used NSMutableDictionary but still have a problem, so i sent my code by email to tell me what's the problem

i'd like to ask you if i can generate NGL file for my objects and upload this NGLs files to my server and let my application read it from the internet (streaming) ???
0% like this - 0/0

@dineybomfim

Posts: 571

NGLAdmin

Sat, Aug 4 2012


In response to: @Khaled_Mahmoud1

OK,

Yes you can. We'll have an tool to generate NGL files, but for now you can take the generated files inside the <ApplicationFolder>/Library/NinevehGL
0% like this - 0/0

@Khaled_Mahmoud1

Posts: 16

NGLNewbie

Sat, Aug 4 2012


In response to: @dineybomfim

nice

After uploading my NGLs files can i initializing meshes in ViewdidLoad() methos
by this line of code?

NSString *fullpath = @"http://mydomain.com/myfile.ngl"
MyMesh = [[NGLMesh alloc] initWithFile:fullpath settings:settings delegate:self];

OR is there another way to initialize the meshes from server???
0% like this - 0/0

@dineybomfim

Posts: 571

NGLAdmin

Sat, Aug 4 2012


In response to: @Khaled_Mahmoud1

No,

NinevehGL doesn't work with URL or any other kind of online path.
This probably will never be a feature. Working with online contents has a loot of implicit behaviors and a whole set of things that has nothing to do with 3D stuff. So this is not our business.

Remember that downloading a 3D content involves in download all its related files, like textures.
0% like this - 0/0

@Khaled_Mahmoud1

Posts: 16

NGLNewbie

Sat, Aug 4 2012


@dineybomfim said:


In response to:@Khaled_Mahmoud1

No,

NinevehGL doesn't work with URL or any other kind of online path.
This probably will never be a feature. Working with online contents has a loot of implicit behaviors and a whole set of things that has nothing to do with 3D stuff. So this is not our business.

Remember that downloading a 3D content involves in download all its related files, like textures.


Sorry i can't understand this point
Do you mean that i can't read the generated NGL file directly from the internet.right?
but in the previous post you said

@dineybomfim said:


In response to:@Khaled_Mahmoud1

Yes you can. We'll have an tool to generate NGL files, but for now you can take the generated files inside the <ApplicationFolder>/Library/NinevehGL


So, how can i read this NGL?
0% like this - 0/0

@dineybomfim

Posts: 571

NGLAdmin

Sat, Aug 4 2012


In response to: @Khaled_Mahmoud1

hey buddy, we're talking about two different things here.

1 - NinevehGL is not responsible by the connection and will never be. You must download the file and save it in a local folder, then NinevehGL can load this file and all its related files.

2 - NinevehGL can load 3 kind of files: OBJ, COLLADA and NGL

In future we'll have a tool to generate the NGL files from OBJ or COLLADA directly from your desktop. However even now, you can take the NGL file that is generated automatically inside the folder <ApplicationFolder>/Library/NinevehGL.

If you take a NGL file from there and try to load it in the same way as you do with OBJ or COLLADA this will work nice.
0% like this - 0/0

@Khaled_Mahmoud1

Posts: 16

NGLNewbie

Sat, Aug 4 2012


In response to: @dineybomfim

nice, i understood now
Is NGLs files faster than OBJs files in loading and initialization?
Do you think that it's the best way for me?

Thank you again
0% like this - 0/0

@dineybomfim

Posts: 571

NGLAdmin

Sat, Aug 4 2012


In response to: @Khaled_Mahmoud1

Take a look at this video:
http://www.youtube.com/watch?v=ViGz59b6ljs

Or continue reading the "Lessons:Features"
http://nineveh.gl/docs/tutorials/

Or even run the project "Binary" inside the folder "NinevehGL Lessons".

The NGL binary file is always the best option, it can be 100X faster than any other file. NinevehGL will always use this binary file instead of the original one after the first run of the app. The result for the final user is absolutely amazing, a huge improvement in the application loading time.
0% like this - 0/0

@Khaled_Mahmoud1

Posts: 16

NGLNewbie

Mon, Aug 13 2012


In response to: @dineybomfim

Thank you for your help ... it is working very well now
0% like this - 0/0

@dineybomfim

Posts: 571

NGLAdmin

Thu, Aug 16 2012


In response to: @Khaled_Mahmoud1

Glad to know that.
If you need something else, just ask.
0% like this - 0/0

@bhartiya_varun

Posts: 27

NGLNewbie

Fri, Nov 9 2012


In response to: @dineybomfim

My application seems to crash frequently in drawView..

Here is the scenario in which this happens:

I load the viewController,
Then dispatch a block on a different thread (Which is downloading models from internet) and then init meshes. This is done to ensure that UI is still active on main thread.
If user clicks on back button, the dealloc of view controller is called. But it never stops calling drawView and the application crashes. .
"message sent to deallocated instance 0x2ec62e30"

Can you help me understand what am i doing wrong?

0% like this - 0/0

@bhartiya_varun

Posts: 27

NGLNewbie

Fri, Nov 9 2012


In response to: @bhartiya_varun

I think it crashes mostly when the init mesh is called but controller is deallocated before mesh loading is finished..

Could you please help?
0% like this - 0/0

@dineybomfim

Posts: 571

NGLAdmin

Fri, Nov 16 2012


In response to: @bhartiya_varun

Yes, probably it will crash. Who is holding your NGLView?
Remember that all the NinevehGL render process is asynchronous and it will run on another thread.

It will stop automatically, but if you think this is your problem, you can pause the NGLView render on "viewWillDisappear".
0% like this - 0/0
Technology

NinevehGL is a 3D engine built right on top of OpenGL ES and it uses all the programmable pipeline power, making it easy for you to create great application with shaders.

Share on


Follow NinevehGL
Fastest way to contact us:

Copyright © 2011 db-in. All rights reserved.