Ignore:
Timestamp:
03/16/21 23:59:15 (4 years ago)
Author:
Maciej Komosinski
Message:

Added a function to get voxels of sampled Model geometry from script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/model/geometry/modelgeoclass.cpp

    r999 r1111  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2016  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    1111static ParamEntry modelgeo_paramtab[] =
    1212{
    13         { "Creature: Geometry", 1, 5, "ModelGeometry",
     13        { "Creature: Geometry", 1, 6, "ModelGeometry",
    1414        "Approximately estimates sizes, volume, and area of a Model based on the geometry of its parts.\n"
    1515        "Example usage:\n"
     
    2222        { "volume", 0, PARAM_NOSTATIC | PARAM_USERHIDDEN, "volume", "p f()", PROCEDURE(p_volume), },
    2323        { "area", 0, PARAM_NOSTATIC | PARAM_USERHIDDEN, "area", "p f()", PROCEDURE(p_area), },
     24        { "voxels", 0, PARAM_NOSTATIC | PARAM_USERHIDDEN, "voxels", "p oVector()", PROCEDURE(p_voxels), },
    2425        { "sizesAndAxes", 0, PARAM_NOSTATIC | PARAM_USERHIDDEN, "sizesAndAxes", "p oVector()", PROCEDURE(p_sizesandaxes), "The returned vector contains XYZ (sizes) and Orient (axes) objects." },
    2526        { 0, 0, 0, },
     
    3334
    3435ModelGeometry::ModelGeometry(ModelObj *mo)
    35 :par(modelgeo_paramtab, this)
     36        :par(modelgeo_paramtab, this)
    3637{
    3738        cached_for_density = -1; //invalid value, will be updated on first request
     
    5657        cached_area = -1;
    5758        cached_sizes.x = -1;
     59        cached_voxels.setEmpty();
    5860}
    5961
     
    7476        if (m != NULL)
    7577        {
    76                 if (m->getShapeType() == Model::SHAPETYPE_BALL_AND_STICK)
    77                         {
     78                if (m->getShapeType() == Model::SHAPETYPE_BALL_AND_STICK)
     79                {
    7880                        Model *converted = new Model;
    7981                        converted->open();
    8082                        converted->buildUsingSolidShapeTypes(*m, Part::SHAPE_CYLINDER, 0.2);
    8183                        converted->close();
    82                         m=converted;
    83                         }
     84                        m = converted;
     85                }
    8486                ModelGeometry *mg = new ModelGeometry((ModelObj*)m);
    8587                mg->density = density;
     
    106108}
    107109
     110void ModelGeometry::p_voxels(ExtValue *args, ExtValue *ret)
     111{
     112        onDensityChanged();
     113        if (cached_voxels.isEmpty()) //calculate if invalid
     114                cached_voxels = ModelGeometryInfo::getVoxels(*model, density);
     115        ret->setObject(cached_voxels);
     116}
     117
    108118void ModelGeometry::p_sizesandaxes(ExtValue *args, ExtValue *ret)
    109119{
Note: See TracChangeset for help on using the changeset viewer.