analitics

Pages

Monday, December 12, 2022

OpenAI knows how to write source code for Blender 3D.

I tested the new OpenAI chat from with this question:
Please write a 3d blender script in Python that moves a camera around an object 360 degrees facing it.

import bpy

# Set the object that the camera will orbit around
target_object = bpy.data.objects["MyObject"]

# Set the starting position for the camera
camera = bpy.data.objects["Camera"]
camera.location = (0, 0, 5)

# Set the number of degrees to rotate the camera around the object
degrees = 360

# Set the distance that the camera should be from the object
distance = 5

# Set the speed at which the camera should orbit
speed = 1

# Set the direction in which the camera should orbit (1 for clockwise, -1 for counter-clockwise)
direction = 1

# Calculate the number of frames needed for the camera to orbit
# around the object by the desired number of degrees
num_frames = degrees / speed

# Set the camera to track the object
bpy.ops.object.select_all(action="DESELECT")
camera.select_set(True)
bpy.context.view_layer.objects.active = camera
bpy.ops.object.track_set(type="TRACKTO")

# Animate the camera orbiting around the object
for frame in range(0, num_frames):
    # Set the current frame
    bpy.context.scene.frame_set(frame)

    # Calculate the new position for the camera based on its distance from the object
    x = distance * math.sin(math.radians(frame*speed*direction))
    y = distance * math.cos(math.radians(frame*speed*direction))
    camera.location = (x,y,0)
I tested with the latest version of Blender 3D and it works well with some small changes it can be improved.
This error for this script:
Python: Traceback (most recent call last):
...
TypeError: 'float' object cannot be interpreted as an integer
If you ask more than once you will get different source code and I encountered a network error.
I tried several times and the network error did not let me take the more complex and complete source code.

Python 3.10.2 : Quickstart with streamlit python package.

In today's tutorial, I will give you a brief introduction to the streamlit packet.
Streamlit turns data scripts into shareable web apps in minutes. All in pure Python. No front‑end experience required.
Let's install with the pip tool:
pip install streamlit
After installation, I tested their example with the following command:
python -m streamlit hello
The result in the browser will be this:
You can create a working folder to add a python file called myapp001.py with the following continue:
import streamlit as st 

st.write("""
#testing streamlit
""")
To run this python file with streamlit use the following command:
python -m streamlit run myapp001.py

  Welcome to Streamlit!

  If you’d like to receive helpful onboarding emails, news, offers, promotions,
  and the occasional swag, please enter your email address below. Otherwise,
  leave this field blank.

  Email:  catafest@yahoo.com

  You can find our privacy policy at https://streamlit.io/privacy-policy

  Summary:
  - This open source library collects usage statistics.
  - We cannot see and do not store information contained inside Streamlit apps,
    such as text, charts, images, etc.
  - Telemetry data is stored in servers in the United States.
  - If you'd like to opt out, add the following to %userprofile%/.streamlit/config.toml,
    creating that file if necessary:

    [browser]
    gatherUsageStats = false


  You can now view your Streamlit app in your browser.
...