Jump to content

Do picks conserve entity keys?


L B
 Share

Recommended Posts

I'm trying the following code. When I middle-click, it creates a warrior at pick position and assigns its "canSelect" key to "true". When I click, it checks the "canSelect" entity of the key to know if it is selectable. However, that key checking always returns the default value (a.k.a. empty string), as if the model didn't keep its keys through the raycast.

 

Note: It's C#, but the syntax is very readable, so I assume you can all read it.

using System;
using System.Collections.Generic;
using Aerora.Logic;
using Leadwerks;

namespace Aerora
{
static class Client
{
	public static bool Run = true;

	private static Entity selected;
	private static Entity Selected
	{
		get
		{
			return selected;
		}
		set
		{
			if (Selected != null)
			{
				Selected.Color = Color.White;
			}

			selected = value;
			Selected.Color = Color.Red;
		}
	}

	public static void Main(string[] args)
	{
		Engine.Initialize(DisplayMode.Window);
		Framework.Initialize();
		Filtering.Optimize();
		FileSystem.Initialize(@"C:\Program Files\Aerora");

		Framework.Effects.Bloom.Enabled = true;
		Framework.Effects.VolumetricLighting.Enabled = true;
		Framework.StatisticMode = StatisticMode.FrameRate;

		Scene scene = new Scene("abstract::Dust Valley.sbx", Framework.Camera);
		Explorer explorer = new Explorer(Framework.Camera);
		Random r = new Random();

		List<Model> warriors = new List<Model>();

		while (Client.Run && !Window.HasRequestedClose)
		{
			explorer.Update();

			Pick pick = new Pick(Framework.Camera, Mouse.X, Mouse.Y, 5000);

			if (Mouse.ButtonHit(MouseButton.Middle))
			{
				Model warrior = new Model("abstract::warrior_character_skin.gmf")
				{
					Position = pick.Position,
					ViewRange = ViewRange.Infinite,
					Scale = 0.3f,
					Rotation = new Vector3(0, r.Next(), 0)
				};

				warrior.Keys["canSelect"] = "true";
				//pick.Entity.Keys["canSelect"] == "true"; // Returns true.

				warriors.Add(warrior);
			}
			else if (Mouse.ButtonHit(MouseButton.Left))
			{
				if (pick.Entity.Keys["canSelect"] == "true") // Returns false.
				{
					Selected = pick.Entity;
				}
			}

			foreach (Model warrior in warriors)
			{
				warrior.Animate(Timing.Time / 20);
			}

			Timing.Update();
			Framework.Update();
			Framework.Render();
			Graphics.Flip();
		}

		Framework.Terminate();
		Engine.Terminate();
	}
}
}

Link to comment
Share on other sites

I can't remember off the top of my head, but one is the parent of the other, and I can't remember what pick.entity returns (mesh or model)

 

It's always a trial and error when I have to do this because I can't remember the order.

 

I actually find that kind of annoying. What is the point of the model part of that? Why isn't it all just a mesh?

Link to comment
Share on other sites

Hi,

I think the picked thing is mesh. I usually use 2 ways to access the model from its mesh. (in LUA actually bt I hope it helps)

 

1 - when I create my model I access the mesh with this command :

 

local mymesh=GetChild(mymodel,1)

 

then I set its Target to my model, using SetTarget command. so I can access the model from the picked mesh, with GetTarget command.

 

2 - There is a LUA function in "scripts\utilities.lua" called GetMeshModel. its a simple loop to get model from its mesh. I think you can use a similar code in any other language.

 

I hope it helps.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...