Last active
January 24, 2024 16:48
-
-
Save p2or/bbbe219451825e8f8bb778737092482a to your computer and use it in GitHub Desktop.
#Blender - Prototype to capture the output of a C++ program supplied by an add-on
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ##### BEGIN GPL LICENSE BLOCK ##### | |
# | |
# This program is free software; you can redistribute it and/or | |
# modify it under the terms of the GNU General Public License | |
# as published by the Free Software Foundation; either version 2 | |
# of the License, or (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program; if not, write to the Free Software Foundation, | |
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
# | |
# ##### END GPL LICENSE BLOCK ##### | |
bl_info = { | |
"name": "Add-on Template", | |
"description": "", | |
"author": "p2or", | |
"version": (0, 4), | |
"blender": (3, 0, 0), | |
"location": "3D View > Tools", | |
"warning": "", # used for warning icon and text in addons panel | |
"doc_url": "https://blender.stackexchange.com/a/57332", | |
"tracker_url": "https://gist.github.com/p2or/2947b1aa89141caae182526a8fc2bc5a", | |
"support": "COMMUNITY", | |
"category": "Development" | |
} | |
import bpy | |
from pathlib import Path | |
# ------------------------------------------------------------------------ | |
# Operators | |
# ------------------------------------------------------------------------ | |
class WM_OT_HelloWorld(bpy.types.Operator): | |
bl_label = "Report Values" | |
bl_idname = "wm.hello_world" | |
def execute(self, context): | |
from subprocess import PIPE, Popen | |
out, err = Popen(app, stdout=PIPE).communicate() | |
x_values, y_values, z_values = [],[],[] | |
out = out.splitlines() | |
for line in out: | |
line = line.strip() | |
columns = line.split() | |
x_values.append(float(columns[0])) | |
y_values.append(float(columns[1])) | |
z_values.append(float(columns[2])) | |
print (z_values) | |
self.report({'INFO'}, ", ".join(map(str, z_values))) | |
return {'FINISHED'} | |
# ------------------------------------------------------------------------ | |
# Panel in Object Mode | |
# ------------------------------------------------------------------------ | |
class OBJECT_PT_CustomPanel(bpy.types.Panel): | |
bl_label = "My Panel" | |
bl_idname = "OBJECT_PT_custom_panel" | |
bl_space_type = "VIEW_3D" | |
bl_region_type = "UI" | |
bl_category = "Tools" | |
bl_context = "objectmode" | |
@classmethod | |
def poll(self,context): | |
return context.object is not None | |
def draw(self, context): | |
layout = self.layout | |
layout.use_property_split = True | |
layout.use_property_decorate = False # No animation. | |
layout.label(text="Path to executable: " + str(app)) | |
layout.operator("wm.hello_world") | |
layout.separator() | |
# ------------------------------------------------------------------------ | |
# Registration | |
# ------------------------------------------------------------------------ | |
# Path to the app | |
app = Path(__file__).parent / "random-numbers" | |
classes = ( | |
WM_OT_HelloWorld, | |
OBJECT_PT_CustomPanel, | |
) | |
def register(): | |
from bpy.utils import register_class | |
for cls in classes: | |
register_class(cls) | |
import stat | |
app.chmod(app.stat().st_mode | stat.S_IEXEC) | |
#os.chmod(str(app), st.st_mode | stat.S_IEXEC) | |
def unregister(): | |
from bpy.utils import unregister_class | |
for cls in reversed(classes): | |
unregister_class(cls) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> // std::cout | |
#include <vector> // std::vector | |
#include <ctime> // std::time | |
#include <cstdlib> // std::rand, std::srand | |
int main () { | |
std::vector<float> z(10); | |
float x = 0.171; | |
float y = 0.324; | |
// iteration to store random numbers | |
std::srand (static_cast <unsigned> (std::time(0))); | |
for (std::vector<float>::iterator i = z.begin(); i != z.end(); i++){ | |
*i = static_cast <float> (rand()) / static_cast <float> (RAND_MAX); | |
} | |
// iteration to print x y z values | |
for (std::vector<float>::iterator i = z.begin(); i != z.end(); i++){ | |
std::cout << (*i * x) << " " << (*i * y) << " " << *i << "\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment