[Release] X3DEditor - Buildmode Purpose

Started by umar4911, Jul 19, 2020, 06:08 PM

Previous topic - Next topic

umar4911

X3DEditor

I've seen VCMP scripters who are working with the GUI are not so familiar with the 3D elements. Since it is a part of my upcoming release, I thought to share it. This script is originally made for scripters who creates GUI in buildmode. Using this snippet, you can easily find the position, rotation and size of a 3D Element.

Note: This only supports DecUI

Understanding controls

It has total 3 types;
  • Position
  • Rotation
  • Size

Position
In order to enter the position changing mode, press 1 from keyboard.

Arrow up - Moves the element forward
Arrow down - Moves the element backward
Arrow left - Moves the element left
Arrow right - Moves the element right
Page up - Moves the element vertically upwards
Page down - Moves the element vertically downwards


Rotation
In order to enter the rotation changing mode, press 2 from keyboard.

Arrow Keys - Change the rotation respectively
Delete - Horizontally rotates to the left (backward)
Page down - Horizontally rotates to the right (forward)



Size
In order to enter the Size changing mode, press 3 from keyboard.

Arrow up - Decreases the size vertically
Arrow down - Increases the size vertically
Arrow left - Decreases the size horizontally
Arrow right - Increases the size horizontally


Saving & Exporting
In order to stop editing the element and export the data, press Backspace key.
This will return print the values and also copy them to the clipboard

Youtube Video

https://www.youtube.com/watch?v=e5k-ZElC55U


Code and example



The code and example is present on the Github Repository.



I am gamer, programmer and hacker. Try to find me!
xD

Murdock


UncleRus

I LoperkinDead.My brothers scripters TimyrSem,VladSem

habi

How is this 3D Texts created. Suppose one creates a 3D text at downtown, so does the text is staying at downtown forever or the text comes with player when he move?

What happens when we shoot the text? ( Nothing. right? )

can you say in laymans terms what is DecUI.

I hope my questions will be useful for some others also

umar4911

Quote from: habi on Jul 20, 2020, 03:00 PMHow is this 3D Texts created. Suppose one createsHow is this 3D Texts created. Suppose one creates a 3D text at downtown, so does the text is staying at downtown forever or the text comes with player when he move?
As said above, this is not made for servers releases. It is originally made for buildmode so players can easily get the position, rotation and size of the 3D Elements. In Editing mode, when Backspace key is pressed, the element stops moving and with copying to the clipboard, prints out it's values. You can just paste those lines in the code and run it in normal servers. An example is given in the wiki of how you need to load it and explained its usage in the video.


Quote from: habi on Jul 20, 2020, 03:00 PMWhat happens when we shoot the text? ( Nothing. right? )
Yep nothing


Quote from: habi on Jul 20, 2020, 03:00 PMcan you say in laymans terms what is DecUI.
There is already a well detailed topic of DecUI available.
If you ask me, I'll say it's an easy and better way to script gui with less code and more options.
I am gamer, programmer and hacker. Try to find me!
xD

NewK

Nice work umar. Nice to see more people taking advantage of buildmode to create stuff like this.

There's a 2 things about DecUI internals you should probably know about which will help you improve your editor.

1) The code you're using at the moment will work for all GUIElements but will not work for DecUI components (Grid, Datatable, Circle,  Combobox, etc...). This is because when you do "typeof e" for a DecUI component, it will return "instance" because DecUI components are classes. However, all DecUI components are wrapped in a GUICanvas with the exact same ID as the component. So you just have to check if typeof returns "instance" and if it does, you build the code as if it's a GUICanvas.

2) When printing/copying code to the clipboard, you should avoid additional lookups and use a local variable instead. Avoid doing this:

UI.Label("newLabel").Position3D  = ...
UI.Label("newLabel").Rotation3D = ...
UI.Label("newLabel").Size3D   = ...

and do this instead:
local newLabel = UI.Label("newLabel");
newLabel.Position3D  = ...
newLabel.Rotation3D =  ...
newLabel.Size3D   = ...

This will be faster and is a good optimization to keep in mind when working with DecUI in general, because every time you do UI<Type>(ID) to fetch something, a tree traversal will be made to find the ID you passed, and if you repeat UI.Label("newLabel") 3 times, you will be making 3 unecessary searches. It's better to just do the search once, save it in a variable ( local always, never global). And then just re-use the same variable. This is an optimization which seems small if you dont  have alot of GUIElements created, but once you start having alot of GUIElements this will make a big difference.

umar4911

Quote from: NewK on Jul 21, 2020, 12:29 AMNice work umar. Nice to see more people taking advantage of buildmode to create stuff like this.

There's a 2 things about DecUI internals you should probably know about which will help you improve your editor.

1) The code you're using at the moment will work for all GUIElements but will not work for DecUI components (Grid, Datatable, Circle,  Combobox, etc...). This is because when you do "typeof e" for a DecUI component, it will return "instance" because DecUI components are classes. However, all DecUI components are wrapped in a GUICanvas with the exact same ID as the component. So you just have to check if typeof returns "instance" and if it does, you build the code as if it's a GUICanvas.

2) When printing/copying code to the clipboard, you should avoid additional lookups and use a local variable instead. Avoid doing this:

UI.Label("newLabel").Position3D  = ...
UI.Label("newLabel").Rotation3D = ...
UI.Label("newLabel").Size3D   = ...

and do this instead:
local newLabel = UI.Label("newLabel");
newLabel.Position3D  = ...
newLabel.Rotation3D =  ...
newLabel.Size3D   = ...

This will be faster and is a good optimization to keep in mind when working with DecUI in general, because every time you do UI<Type>(ID) to fetch something, a tree traversal will be made to find the ID you passed, and if you repeat UI.Label("newLabel") 3 times, you will be making 3 unecessary searches. It's better to just do the search once, save it in a variable ( local always, never global). And then just re-use the same variable. This is an optimization which seems small if you dont  have alot of GUIElements created, but once you start having alot of GUIElements this will make a big difference.
Hey mate. Thank you for pointing those things out. I updated  the respository. It now supports DecUI components and does the optimization.
I am gamer, programmer and hacker. Try to find me!
xD