2

I am having 2D design in microstation and I wanted to represent this design in web using any tool(javascript/Unity 3D or any other) where the web tool will not have all the functionality but basic functionality like reshaping or adding a new shape should be available.

As of now, my approach is once I created a design in microstation then I am capturing properties of shapes like the cordinates of a line and now using these coordinates I wanted to represent in the browser since this is a 2D design so it will be plotted in some location (x,y) for example I have created a line in microstation from (2,2) to (10,10) so it will be a straight line and I have all the coordinates I tried redrawing it in Unity which am able to do but I am facing issue to change the length from (2,2) to (20,20) by mouse click. And my goal is to do it in runtime, not in Unity editor tool.

This is an example of a straight line I wanted to do it for all geometric shape,any guidance would be appreciated.

As of now am trying Unity to do so but struggling in the edit part is there a way to achieve this in unity?

I also looked at various javascript libraries like konvaJS, makerJS, ThreeJS, etc. but except konvajs none of the other library provide facilities like reshaping, in Konva also creating shape using a mouse not found any solution for this.

Can we achieve this by any of the two approaches, of course, am not looking for all functionality only a few custom functionality, if yes which approach will be the best, and which tool should I proceed with? Any guidance will be helpful.

Darren
  • 138
  • 1
  • 8
techipank
  • 432
  • 4
  • 17
  • Not everyone here knows Unity could understand three.js, konvajs and microstation. What are them? I never use konvajs and microstation and don't understand what you want to achieve after switching to Unity. https://stackoverflow.com/help/how-to-ask – zwcloud Jul 30 '19 at 05:38
  • I agree not everyone here knows Unity could understand JS library, that's the reason i asked two questions, how it can be done with Unity or Javascript, if there is Javascript guy he can answer else Unity guy will answer and best of the solutions will be accepted – techipank Jul 30 '19 at 05:46
  • I mean you should be more concrete on your business logic: *created design in microstation then i am capturing properties of shapes like cordinates of a line and now using these coordinates*, what is *capturing properties of shapes*? How to use *these coordinates*? What do you want to do with these coordinates? – zwcloud Jul 30 '19 at 06:30
  • @zwcloud thanks for the headsups as suggested edited my question any help would be appreciated. – techipank Jul 30 '19 at 06:40

1 Answers1

0

To draw a line-segment, you can use LineRenderer.

//two points of the line-segment are known (or got from the Transform of GameObject)
Vector3 start;
Vector3 end;

GameObject myLine = new GameObject();
myLine.transform.position = start;
myLine.AddComponent<LineRenderer>();
LineRenderer lr = myLine.GetComponent<LineRenderer>();
lr.material = new Material(Shader.Find("Particles/Alpha Blended Premultiply"));
lr.SetColors(color, color);
lr.SetWidth(0.1f, 0.1f);
lr.SetPosition(0, start);
lr.SetPosition(1, end);

//to change the points of this line
myLine.transform.position = another_start;
lr.SetPosition(0, another_start);
lr.SetPosition(1, another_end);

There are also other solutions:

  • Use scaled cube or capsule primitive.
  • 3rd-party plugins: vectrosity

To get mouse clicked position, use Camera.main.ScreenToWorldPoint(Input.mousePosition).

To determine when your mouse is clicked, use Input.GetMouseButtonUp.

zwcloud
  • 4,546
  • 3
  • 40
  • 69
  • how about reshaping this line in run-time? – techipank Jul 30 '19 at 06:54
  • really thank you for your guidance just one more doubt from where you are getting `another_start` and `another_end` i wanted to capture this using mouse click i don't have value for this i have value for `start` and `end` only something like dragging the length of line – techipank Jul 30 '19 at 06:58
  • @techipank Glad to know that! Please upvote the answer if you think it is useful. – zwcloud Aug 07 '19 at 02:28