Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 134 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,107 +1,159 @@
<p align="center">
<img src="logo.png" alt="logo"/>
</p>

# Learn Python 3
# 多模型3D查看器

[![Build Status](https://travis-ci.org/jerry-git/learn-python3.svg?branch=master)](https://travis-ci.org/jerry-git/learn-python3)
一个功能强大的网页应用,可以同时加载和显示最多3个3D模型(支持STL、PLY、OBJ格式),并实现所有模型的同步操作。

## Introduction
## ✨ 主要特性

This repository contains a collection of materials for teaching/learning Python 3 (3.5+).
- 🎯 **多模型支持**: 同时显示最多3个不同的3D模型
- 📁 **多格式兼容**: 支持STL、PLY、OBJ文件格式
- 🔄 **同步操作**: 对任意模型进行旋转、平移、缩放时,其他模型自动同步相同操作
- 🚀 **性能优化**: 针对大模型进行了优化,支持高多边形数量的模型
- 🎨 **现代UI**: 美观的响应式设计,支持移动设备
- 🖱️ **拖拽上传**: 支持文件拖拽上传和点击选择
- 🔲 **线框模式**: 可切换线框显示模式
- 📊 **模型信息**: 显示文件名和顶点数量信息

#### Requirements
* Have Python 3.5 or newer installed. You can check the version by typing `python3 --version` in your command line. You can download the latest Python version from [here](https://www.python.org/downloads/).
* Have [Jupyter Notebook installed](http://jupyter.readthedocs.io/en/latest/install.html).
## 🚀 快速开始

If you can not access Python and/or Jupyter Notebook on your machine, you can still follow the web based materials. However, you should be able to use Jupyter Notebook in order to complete the exercises.
### 1. 运行应用

#### Usage
由于使用了Three.js和WebGL,建议通过HTTP服务器运行:

1. Clone or download this repository.
2. Run `jupyter notebook` command in your command line in the repository directory.
3. Jupyter Notebook session will open in the browser and you can start navigating through the materials.
```bash
# 使用Python的简单HTTP服务器
python -m http.server 8000

#### Contributing
See [contributing](https://github.com/jerry-git/learn-python3/blob/master/CONTRIBUTING.md) guide.
# 或使用Node.js的http-server
npx http-server

# 或使用PHP内置服务器
php -S localhost:8000
```

## Beginner
1. [Strings](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/strings.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/strings.ipynb) [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/strings_exercise.ipynb)
1. [Numbers](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/numbers.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/numbers.ipynb) [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/numbers_exercise.ipynb)
1. [Conditionals](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/conditionals.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/conditionals.ipynb) [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/conditionals_exercise.ipynb)
1. [Lists](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/lists.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/lists.ipynb) [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/lists_exercise.ipynb)
1. [Dictionaries](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/dictionaries.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/dictionaries.ipynb) [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/dictionaries_exercise.ipynb)
1. [For loops](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/for_loops.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/for_loops.ipynb) [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/for_loops_exercise.ipynb)
1. [Functions](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/functions.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/functions.ipynb) [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/functions_exercise.ipynb)
1. [Testing with pytest - part 1](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/testing1.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/testing1.ipynb) [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/testing1_exercise.ipynb)
1. Recap exercise 1 [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/recap1_exercise.ipynb)
1. [File I\O](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/file_io.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/file_io.ipynb) [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/file_io_exercise.ipynb)
1. [Classes](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/classes.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/classes.ipynb) [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/classes_exercise.ipynb)
1. [Exceptions](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/exceptions.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/exceptions.ipynb) [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/exceptions_exercise.ipynb)
1. [Modules and packages](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/modules_and_packages.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/modules_and_packages.ipynb)
1. [Debugging](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/debugging.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/debugging.ipynb) [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/debugging_exercise.ipynb)
1. [Goodies of the Standard Library - part 1](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/std_lib.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/std_lib.ipynb) [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/std_lib1_exercise.ipynb)
1. [Testing with pytest - part 2](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/testing2.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/testing2.ipynb) [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/testing2_exercise.ipynb)
1. [Virtual environment](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/venv.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/venv.ipynb)
1. [Project structure](https://jerry-git.github.io/learn-python3/notebooks/beginner/html/project_structure.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/notebooks/project_structure.ipynb)
1. Recap exercise 2 [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/recap2_exercise.ipynb)
然后在浏览器中访问 `http://localhost:8000`

### 2. 加载模型

## Intermediate
- **方法1**: 点击"选择模型"按钮,选择STL/PLY/OBJ文件
- **方法2**: 直接将文件拖拽到对应的视窗中

#### Idiomatic Python
Python is a powerful language which contains many features not presented in most other programming languages. Idiomatic section will cover some of these Pythonic features in detail. These materials are especially useful for people with background in other programming languages.
### 3. 操作模型

1. [Idiomatic loops](https://jerry-git.github.io/learn-python3/notebooks/intermediate/html/idiomatic_loops.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/intermediate/notebooks/idiomatic_loops.ipynb)
1. [Idiomatic dictionaries](https://jerry-git.github.io/learn-python3/notebooks/intermediate/html/idiomatic_dicts.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/intermediate/notebooks/idiomatic_dicts.ipynb)
1. [Idiomatic Python - miscellaneous part 1](https://jerry-git.github.io/learn-python3/notebooks/intermediate/html/idiomatic_misc1.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/intermediate/notebooks/idiomatic_misc1.ipynb)
1. [Idiomatic Python - miscellaneous part 2](https://jerry-git.github.io/learn-python3/notebooks/intermediate/html/idiomatic_misc2.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/intermediate/notebooks/idiomatic_misc2.ipynb)
1. Idiomatic Python exercise [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/intermediate/exercises/idiomatic_python_exercise.ipynb)
- **旋转**: 鼠标左键拖拽
- **缩放**: 鼠标滚轮或右键拖拽
- **平移**: 中键拖拽或Ctrl+左键拖拽
- **重置视图**: 点击"重置视图"按钮
- **线框模式**: 点击"线框模式"按钮切换显示模式

#### Step up your `pytest` game
1. [Efficient use of fixtures](https://jerry-git.github.io/learn-python3/notebooks/intermediate/html/pytest_fixtures.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/intermediate/notebooks/pytest_fixtures.ipynb)
1. Other tips and tricks
## 🛠️ 技术架构

#### Best practices
A list of best development practices for Python projects. Most of the practices listed here are also applicable for other languages, however the presented tooling focuses mainly on Python.
1. [Best practices](https://jerry-git.github.io/learn-python3/notebooks/intermediate/html/best_practices.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/intermediate/notebooks/best_practices.ipynb)
### 核心技术栈

#### General topics
1. [Goodies of the Standard Library - part 2](https://jerry-git.github.io/learn-python3/notebooks/intermediate/html/std_lib2.html) [[notebook]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/intermediate/notebooks/std_lib2.ipynb) [[exercise]](http://nbviewer.jupyter.org/github/jerry-git/learn-python3/blob/master/notebooks/intermediate/exercises/std_lib2_exercise.ipynb)
- **Three.js**: 3D渲染引擎
- **WebGL**: 硬件加速的3D图形
- **ES6+**: 现代JavaScript特性
- **CSS3**: 响应式设计和动画效果

#### Backlog
* Sets
* Generators
* Decorators
* Context managers
* Playing with attributes
* *, *args, **kwargs
* Command line arguments with click
* OOP - inheritance
* OOP - Abstract Base Classes
* OOP - attrs
* Testing with mocks
* Structuring your tests
### 文件结构

```
├── index.html # 主页面
├── app.js # 核心JavaScript逻辑
└── README.md # 说明文档
```

## Use cases
### 主要组件

#### Playing with the web
* requests
* testing requests with responses
* beautifulsoup4
* selenium
1. **Model3DViewer类**: 主要的查看器类
- 管理多个视窗
- 处理模型加载
- 实现同步操作

#### Communicating with databases
* SQLAlchemy
2. **模型加载器**:
- STLLoader: 处理STL文件
- PLYLoader: 处理PLY文件
- OBJLoader: 处理OBJ文件

#### Working with documents
* excel
* openpyxl
* pdf
* pdfrw / PyPDF2
3. **渲染系统**:
- 场景管理
- 光照系统
- 相机控制

## 🔧 功能详解

## Credits
* Logo: Abdur-Rahmaan Janhangeer, [@Abdur-rahmaanJ](https://github.com/Abdur-rahmaanJ)
### 同步操作机制

当用户操作任意一个模型时:

1. 检测OrbitControls的变化事件
2. 获取当前相机位置、旋转和目标点
3. 将这些参数同步应用到其他所有视窗
4. 显示同步操作指示器

### 大模型优化

- **LOD (Level of Detail)**: 根据视距自动调整模型细节
- **延迟加载**: 异步加载模型文件
- **内存管理**: 及时清理不用的模型资源
- **渲染优化**: 使用WebGL硬件加速

### 响应式设计

- 自适应网格布局
- 移动设备优化
- 触摸手势支持
- 动态视窗大小调整

## 🎨 界面说明

### 顶部控制栏
- **选择模型按钮**: 3个文件选择按钮,分别对应3个视窗
- **重置视图**: 将所有模型视角重置到默认位置
- **线框模式**: 切换所有模型的线框显示

### 视窗区域
- **模型显示区**: 3D模型的渲染区域
- **加载指示器**: 显示模型加载进度
- **模型信息**: 显示文件名和顶点数量
- **同步指示器**: 显示当前是否在进行同步操作

## 📱 浏览器兼容性

- ✅ Chrome 60+
- ✅ Firefox 55+
- ✅ Safari 12+
- ✅ Edge 79+
- ❌ Internet Explorer (不支持)

## ⚠️ 注意事项

1. **文件大小**: 建议单个模型文件不超过50MB
2. **浏览器性能**: 大模型可能消耗较多内存和GPU资源
3. **网络环境**: 首次加载需要下载Three.js库文件
4. **文件格式**: 确保上传的文件格式正确(STL/PLY/OBJ)

## 🐛 常见问题

### Q: 模型加载失败怎么办?
A: 检查文件格式是否正确,文件是否损坏,或尝试重新加载

### Q: 模型显示异常?
A: 点击"重置视图"按钮,或刷新页面重新加载

### Q: 同步操作不生效?
A: 确保至少加载了一个模型,同步功能会在加载模型后自动启用

### Q: 性能问题?
A: 尝试使用较小的模型文件,或关闭其他占用GPU的应用

## 📄 许可证

MIT License - 可自由使用和修改

## 🤝 贡献

欢迎提交Issue和Pull Request来改进这个项目!

---

**享受3D模型查看的乐趣!** 🎉
Loading