Создаём приложение с 3D моделью при помощи VIKTOR

Прочее

In this part of the tutorial, we will create a 3D model of the radio tower using the geometry module. Before we start building the 3D model, let’s check out what the current application looks like.

In your browser,

  1. Click on “Create”.
  2. Fill in a name in the pop-up
  3. Click “Create and open”

You should now see an empty page. So let’s start creating our 3D model.

Add a 3D model to your app

First, we will visualize the base of the radio tower. The base will just be a cylinder, which will have a height and a diameter. The first part is a bit slow, but I promise that we will draw the rest of the tower at lighting speed.

  1. Go to the folder tower-app and open app.py in your favourite code editors.
  2. Check app.py so that it looks like this:
from viktor.core import ViktorController
from viktor.parametrization import ViktorParametrization


class Parametrization(ViktorParametrization): 
    pass


class Controller(ViktorController): 
    label = 'VIKTOR Tutorial'


parametrization = Parametrization

3. On the top, import some additional functions we will need to create the app:

from viktor.geometry import Point, Line, CircularExtrusion, Material, Color
from viktor.views import GeometryView, GeometryResult

4. First we will create a geometry view to show your 3D model and define a function to draw everything. We do this inside your controller like this.

class Controller(ViktorController): 
    label = 'VIKTOR Tutorial'
    
    parametrization = Parametrization
    
    @GeometryView("3D", duration_guess=1)
    def visualize_tower(self, params, **kwargs): 
        """Creates the 3D view and visualizes the Radio Tower"""
        
        return GeometryResult()

Now we will start drawing. First, let’s define 2 reference points we need for our design:

    @GeometryView("3D", duration_guess=1)
    def visualize_tower(self, params, **kwargs):
        """Creates the 3D view and visualizes the Radio Tower"""
        
        base_start = Point(0, 0, 0)
        base_end = Point(0, 0, 50)
        
        return GeometryResult()

To create your base of the tower, we will use CirculerExtrusion, which draws a cylinder following a line between the points base_start and base_end. Under the two point we just created add:

    @GeometryView("3D", duration_guess=1)
    def visualize_tower(self, params, **kwargs):
        """Creates the 3D view and visualizes the Radio Tower"""

        base_start = Point(0, 0, 0)
        line = Line(base_start, base_end)
        base = CircularExtrusion(diameter=5, line=line)
        base_end = Point(0, 0, 50)

        return GeometryResult()

If everything went right, you should be able to see the cylinder in your app. Save the app.py file, go to your app and refresh the page.

0

Автор публикации

не в сети 4 недели

art610

1000K
Lnovus Support
Комментарии: 0Публикации: 38Регистрация: 04-06-2022
Источник
Оцените материал
( Пока оценок нет )
Locus Novus
Добавить комментарий

Авторизация
*
*
Регистрация
*
*
*
Пароль не введен
Генерация пароля