Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
selecting models
Topic Started: Nov 17 2007, 07:19 PM (959 Views)
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
Please put the entire following code into the Left Pressed mouse event of the camera and see if you can select object instances by clicking on them:
Code:
 
var ID;

// Get the mouse position relative to the center of the first view
// and scale it to the (vertical) range from -1 to 1
RelMouseX=(mouse_x-(view_xview[0]+view_wview[0]/2))/(view_hview[0]/2);
RelMouseY=(mouse_y-(view_yview[0]+view_hview[0]/2))/(view_hview[0]/2);
// Calculate the (relative) distance of the viewpoint to the viewplane
ViewPlaneDist=1/tan(degtorad(view/4));
// Calculate the Longitude and Latitude parameter values for the
// GetDistanceToModel(...) function
Angle=degtorad(rotx)+arctan2(RelMouseY,ViewPlaneDist);
Hypotenuse=sqrt(sqr(RelMouseY)+sqr(ViewPlaneDist));
Length=Hypotenuse*cos(Angle);
rotyAdd=arctan2(RelMouseX,Length);
diry=roty+radtodeg(rotyAdd);
RelHeight=Hypotenuse*sin(Angle);
Hypotenuse=sqrt(sqr(RelMouseX)+sqr(Length));
dirx=radtodeg(arctan2(RelHeight,Hypotenuse));
// Find the point on the object instance that the mouse is over
with (ModelObject)
{
 ID=id;
 with (camera)
 {
   distance=GetDistanceToModel(ID,x,y,z+height,dirx,diry);
   if (distance < 100000)
   {
     ID.selected=true;
     PointX=x+sin(degtorad(diry))*cos(degtorad(dirx))*distance;
     PointY=y+cos(degtorad(diry))*cos(degtorad(dirx))*distance;
     PointZ=z+height-sin(degtorad(dirx))*distance;
   }
   else ID.selected=false;
 }
}

And don't forget to replace "ModelObject" with the name of the object.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
spiff88
Advanced Member
[ *  *  * ]
i put it in the left pressed then put that one code u had before in the step to change the ambient if selected=true nothing happened
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
Sorry for the late reply, but anyway I just realized that you can't use the mouse events - yeah I'm getting a bit sleepy, :P.
Change the event to a keypress event and also replace this:
Code:
 
var ID;

with this:
Code:
 
var ID,dirx,diry;

Now it should really work (I just tested it). If you have more questions, I'll check them later.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
spiff88
Advanced Member
[ *  *  * ]
i have a question that goes off the subject, everything is going smooth now all i need to do is make it save into a model file of U3D format how do i do this, also will it also support lights if any are put in?
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
You can only save one model object to a specific *.u3d file; lights cannot be included, or saved to separate *.u3d files.

A model object can be exported to an *.u3d file by adding ExportToU3DFile(...) to your code. You should call this function only once (so don't add it to a Step Event or to a loop) and after the model is set up to look exactly the way you want it to be saved. Also keep in mind that certain properties can't be saved, namely those things that are defined by variables.

Once you're happy with the exported result (you can check it with Dr. Best's model viewer or U3D Studio), you can remove the ExportToU3DFile(...) function from your project file. You could then continue working with the *.u3d file instead of the original model file. In that case you can also remove the code you used to set the appearance of the exported file, at least anything that's not set up through variables.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
spiff88
Advanced Member
[ *  *  * ]
where do i put this? also im not sure what output file means or export resources
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
spiff88
Nov 20 2007, 12:21 AM
where do i put this?

That depends on what you do with the model, to get it to look the way you want it to be saved. It could be as simple as loading the model and immediately exporting it; then you can place the call to ExportToU3DFile(...) right after LoadMesh(), usually in the Create Event.
It could also be that you want to save differently coloured versions of the model. Suppose you do that when pressing a certain key, then you would have to call ExportToU3DFile(...) after the call to SetModelMaterial(...) and/or SetModelMaterialEmissive(...) in that key event.
Have a look at the last piece of code of the Create Event of the object called "model" in the SDK (basicGM6.gm6/basic.gmd); if you applied this "Optional stuff" and called ExportToU3DFile(...) after those functions, the model would be saved with the resulting changes.

spiff88
Nov 20 2007, 12:21 AM
also im not sure what output file means or export resources

OutputFile is simply the name of the *.u3d file you want to save the model to.
If you set ExportResources to true, then all the texture and shader files that your model uses at the moment of export will be included within that *.u3d file. You could then remove these external files from the folder where they currently reside. Be sure to back them up though, as you might need them again later.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
spiff88
Advanced Member
[ *  *  * ]
output file is what the model is saved to? or do u mean saved as such as just naming it.
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
Example:
if you want to save the model of a car to a *.u3d file called "MyCar.u3d" (without password and not including external files), use this:
Code:
 
ExportToU3DFile("MyCar.u3d","",false);

You should then find the file "MyCar.u3d" in the folder from where you ran your program.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
spiff88
Advanced Member
[ *  *  * ]
i did this and it made a u3d file so i went back into the program and loaded it up it only loaded one model when in fact i made 3 when saving it wats wrong
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
As I stated a couple of posts back, you can only save ONE (1) model to a specific *.u3d file. If the 3 models you are trying to save are instances of the same object, then you need to make the OutputFile string different for each instance, or the output file would get overwritten twice and only contain the model that was exported last.
So you need something like this:
Code:
 
var FileName,IdentifierString;

FileName="MyModel";
IdentifierString=string_format(count,3,0);
IdentifierString=string_replace_all(IdentifierString," ","0");
FileName+=IdentifierString+".u3d";
ExportToU3DFile(FileName,"",false);

The above code uses a local variable "count". It gets its value assigned when creating the instance it belongs to, like this for example:
Code:
 
var i;

for (i=1; i <= 3; i+=1)
{
 with (instance_create(ModelObject)) count=i;
}

Now you should find 3 *.u3d files: "MyModel001.u3d", "MyModel002.u3d" and "MyModel003.u3d".
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
spiff88
Advanced Member
[ *  *  * ]
the point of this program is an object placement level editor where u load models up put them where u want since this would pretty hard in a normal model editor anyway and to where u can make pretty detailed placed levels so i dont want to export each model i want to export them all as one file so it could be like a level, and hay if u got an easier program to make levels and place entities that could be saved compatible with u3d please do tell because i dont have a clue where to find something like that exept by building ur own
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
spiff88
Nov 22 2007, 06:31 PM
the point of this program is an object placement level editor

Yes, I had already understood that and it's a good initiative.

spiff88
Nov 22 2007, 06:31 PM
i dont want to export each model i want to export them all as one file so it could be like a level, and hay if u got an easier program to make levels and place entities that could be saved compatible with u3d please do tell because i dont have a clue where to find something like that exept by building ur own

It's not my fault that you cannot save more than 1 model to a *.u3d file. But you can make your own custom file format using GM's text file functions. You can save any variable data you want that way, and even include a string that you can execute when loading this text file, which in turn loads any number of different *.u3d files in sequence. Anyway, it's just an idea.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
spiff88
Advanced Member
[ *  *  * ]
and do u know how to do that?
Offline Profile Quote Post Goto Top
 
spiff88
Advanced Member
[ *  *  * ]
just had an idea would it be possible to group the models as one like they do in model editors that way theyd only be one model?
Offline Profile Quote Post Goto Top
 
« Previous Topic · Questions about Ultimate 3D · Next Topic »
Add Reply